From patchwork Fri Sep 18 17:41:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 273375 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9554C43463 for ; Fri, 18 Sep 2020 17:44:48 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3D44C21707 for ; Fri, 18 Sep 2020 17:44:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iDjqhXrQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3D44C21707 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:35178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kJKRD-0004dM-BE for qemu-devel@archiver.kernel.org; Fri, 18 Sep 2020 13:44:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36162) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kJKNw-0002nA-50; Fri, 18 Sep 2020 13:41:24 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:51654) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kJKNu-0000FL-IT; Fri, 18 Sep 2020 13:41:23 -0400 Received: by mail-wm1-x343.google.com with SMTP id w2so6083905wmi.1; Fri, 18 Sep 2020 10:41:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mHMBZwFybrG3Wb5VMsP3egLDE4ZsHJicDRun+ytDKB4=; b=iDjqhXrQBlXTZoroY32efXfJq2RtOCHrjqnSmbeDF/n0kpABMlZfcq+VaLeYzJgCrr W3YwbCVHvvj4kmI8qUxc9UZWNwbMf9TXN9rmX5nNGDAjXxako0LMrrKGrSSZyl/mqMYS kJ1P1NPL7k72jTlK5YRmMl8xgncf8Qnbl7zVjw82Z7HoSxYBpu55WMl8R18pQ1Sc0QiO ATFT9dulauKeQGFWCKaNZD9DGBow4vpjLKwthnggrKtJRDPsvYiYp4PNjJbWmYr72989 lELbLgt2BaxG3XdDB29Ab31tBmyxxjHnnF7hbEUe9LiL9WelEwu6243XHMn5JCeUjP+1 a4fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=mHMBZwFybrG3Wb5VMsP3egLDE4ZsHJicDRun+ytDKB4=; b=Gbon1O1FB04x8L6aPJts2/C/g8AsUu3maMx0+paiSfwEv6esuOR11O4yCWYJr4JIUv R6thNbN81V7ikx8leg3qqjdes2J1nEURGMINAqpLcLksR+PMQOQQfn0j6gIBwQjZmwOl IdBVyR7oY6Y6ssxKc+s6ukSB8kGP44Ug6XDr7YcktcJu0I1rPlPBBYXvVbX/T6fTtFrd NVz9xJfJOzhjwqVPC71dJyWioowecVbUZvLFhjWwtQ6QAjHAS8I2b2TJJ8vT6+qxL5qO 9xdlV/LRBgUUSOY7L9SWgMnwXC4gkuMOSdI/m1CsITWnsiQ9g9eHpt6mMR3lPXQXTo74 y2MA== X-Gm-Message-State: AOAM533bbJDs+pXBX99O4C2lhqzV3eIXnRZfN31d62hQ8XmlpqtJsaqW rRCjeKyV0DbJrL52S2LSPkJyTJSzouY= X-Google-Smtp-Source: ABdhPJwHDsIzpBjkWdnd7DvWVfxyk62dE3wOvgXi/8eskd5mdSlb9HoSpi5Sq0rl3Rp41AHWjOzBeg== X-Received: by 2002:a05:600c:2182:: with SMTP id e2mr17103210wme.102.1600450880358; Fri, 18 Sep 2020 10:41:20 -0700 (PDT) Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id a81sm6356179wmf.32.2020.09.18.10.41.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2020 10:41:19 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 1/6] hw/sd/sdcard: Add trace event for ERASE command (CMD38) Date: Fri, 18 Sep 2020 19:41:12 +0200 Message-Id: <20200918174117.180057-2-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200918174117.180057-1-f4bug@amsat.org> References: <20200918174117.180057-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::343; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x343.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexander Bulekov , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Trace addresses provided to the ERASE command. Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 2 +- hw/sd/trace-events | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 00128822224..2606b969e34 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -749,7 +749,7 @@ static void sd_erase(SDState *sd) uint64_t erase_start = sd->erase_start; uint64_t erase_end = sd->erase_end; - trace_sdcard_erase(); + trace_sdcard_erase(sd->erase_start, sd->erase_end); if (!sd->erase_start || !sd->erase_end) { sd->card_status |= ERASE_SEQ_ERROR; return; diff --git a/hw/sd/trace-events b/hw/sd/trace-events index a87d7355fb8..96c7ea5e52f 100644 --- a/hw/sd/trace-events +++ b/hw/sd/trace-events @@ -46,7 +46,7 @@ sdcard_reset(void) "" sdcard_set_blocklen(uint16_t length) "0x%03x" sdcard_inserted(bool readonly) "read_only: %u" sdcard_ejected(void) "" -sdcard_erase(void) "" +sdcard_erase(uint32_t first, uint32_t last) "addr first 0x%" PRIx32" last 0x%" PRIx32 sdcard_lock(void) "" sdcard_unlock(void) "" sdcard_read_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" From patchwork Fri Sep 18 17:41:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 305043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF4CFC43463 for ; Fri, 18 Sep 2020 17:44:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5407921707 for ; Fri, 18 Sep 2020 17:44:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Kp8nqvXC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5407921707 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:34932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kJKRB-0004XM-3M for qemu-devel@archiver.kernel.org; Fri, 18 Sep 2020 13:44:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kJKNx-0002nS-6a; Fri, 18 Sep 2020 13:41:25 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:37501) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kJKNv-0000Fg-IO; Fri, 18 Sep 2020 13:41:24 -0400 Received: by mail-wr1-x441.google.com with SMTP id z4so6443834wrr.4; Fri, 18 Sep 2020 10:41:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BM7THxJfGf+b7XY8piPM2aMZEPnFkfmBjlshGc2heOo=; b=Kp8nqvXCh2AozmISeyeO6RDwlKAzJSL4/UIlyk4KnMmav9o4SkaNSVkr13F7XiSFOT Jrbhvq8ydOxDF2UgXw4fKkgVy1fQlgTYA8UIl7OhUxICJhHtC9I3xeU1CVjR22DEjAPs LVHvRmFovAJw0EHBHDTizsxz2Iu04wkd5G/jHvG/70dzTebvNlfiDMzGDlQO25TZZEVm TRTRpDVVoKXFjXM1lzeQU0OxkY33oyd9UTuHkkP3vrqK8DUm1+WnX+CDb7/jhaQtFbDd QQwbYMU6QSX7IhGBGBlqRIZvNGlY374yJJ/ZtE1lyq9IGpRiIwCk9K1HckLVKdI/YRXI LPDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=BM7THxJfGf+b7XY8piPM2aMZEPnFkfmBjlshGc2heOo=; b=plAlL4m2uQQkFDH+GtL/3N3ZJLooGmOqe5K4jcCrOE47kbIvgJAtq8kIr52RX/63Gi NY1QrRzbVpv4iDLf7WKNOQh3DkA/0HkrY1byOvpfVpsCQsSkAAomx9XFAPjpZIesttr1 DRtShcGOmfzmUJtmrgTXyi1nlzC+VtdDatVX2maQgHnYCv90nTvyDmcVgtRd/Fl9VM4a SChVzAVchhYoYGq4iZT9IBOkkNuO9XUewfMBA3mi3QQX59YrOwL70JWDH4cx20kERCWX 8oO8dkTf55H94d480gvV8KOHHtxI0mT7W1AiHgtsMGPoKSXObC9uDA3la3kqlis6rcsn WjeA== X-Gm-Message-State: AOAM533IvKqPKce4hceyUnfUQmfdPy8t2GAKx1XOVkfCX4EpZ1L/rr/r rEcuWJC57kVbR7CaR5L+174eu6pJlQo= X-Google-Smtp-Source: ABdhPJwFXUqbCrZ1defHjZOJmBn1tgb4uX6EPPvWCEpo2HGADi8/i2q75eKBcz3ouS3xDJeiroJ/BA== X-Received: by 2002:adf:df05:: with SMTP id y5mr42456744wrl.39.1600450881480; Fri, 18 Sep 2020 10:41:21 -0700 (PDT) Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id a81sm6356179wmf.32.2020.09.18.10.41.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2020 10:41:20 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 2/6] hw/sd/sdcard: Introduce the INVALID_ADDRESS definition Date: Fri, 18 Sep 2020 19:41:13 +0200 Message-Id: <20200918174117.180057-3-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200918174117.180057-1-f4bug@amsat.org> References: <20200918174117.180057-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::441; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexander Bulekov , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" '0' is used as a value to indicate an invalid (or unset) address. Use a definition instead of a magic value. Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 2606b969e34..30ae435d669 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -53,6 +53,8 @@ #define SDSC_MAX_CAPACITY (2 * GiB) +#define INVALID_ADDRESS 0 + typedef enum { sd_r0 = 0, /* no response */ sd_r1, /* normal response command */ @@ -575,8 +577,8 @@ static void sd_reset(DeviceState *dev) sd->wpgrps_size = sect; sd->wp_groups = bitmap_new(sd->wpgrps_size); memset(sd->function_group, 0, sizeof(sd->function_group)); - sd->erase_start = 0; - sd->erase_end = 0; + sd->erase_start = INVALID_ADDRESS; + sd->erase_end = INVALID_ADDRESS; sd->size = size; sd->blk_len = 0x200; sd->pwd_len = 0; @@ -750,7 +752,8 @@ static void sd_erase(SDState *sd) uint64_t erase_end = sd->erase_end; trace_sdcard_erase(sd->erase_start, sd->erase_end); - if (!sd->erase_start || !sd->erase_end) { + if (sd->erase_start == INVALID_ADDRESS + || sd->erase_end == INVALID_ADDRESS) { sd->card_status |= ERASE_SEQ_ERROR; return; } @@ -763,8 +766,8 @@ static void sd_erase(SDState *sd) erase_start = sd_addr_to_wpnum(erase_start); erase_end = sd_addr_to_wpnum(erase_end); - sd->erase_start = 0; - sd->erase_end = 0; + sd->erase_start = INVALID_ADDRESS; + sd->erase_end = INVALID_ADDRESS; sd->csd[14] |= 0x40; for (i = erase_start; i <= erase_end; i++) { From patchwork Fri Sep 18 17:41:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 273374 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFC22C43464 for ; Fri, 18 Sep 2020 17:48:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2403A21707 for ; Fri, 18 Sep 2020 17:48:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Or9i/vPQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2403A21707 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:42036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kJKUo-0007iZ-UD for qemu-devel@archiver.kernel.org; Fri, 18 Sep 2020 13:48:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36184) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kJKNy-0002ne-2e; Fri, 18 Sep 2020 13:41:26 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:42112) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kJKNw-0000GF-Ln; Fri, 18 Sep 2020 13:41:25 -0400 Received: by mail-wr1-x441.google.com with SMTP id c18so6437635wrm.9; Fri, 18 Sep 2020 10:41:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+lnXOruvwPuxAjkIojj7o4yQ5aFq/OmvzZbaJBwTWHI=; b=Or9i/vPQpsO73usv3qG+KDnRuo2OOMhVmIb/ORV5OOIw4CEUU2qA6gQrsFnGACFAUs MCoXGhi9qC2bCU/1prPvbxdIir2pbkXDJi8rUqNsA/0Xw+YKOyddmToYHLF4PLQ9qWCo YiX2wpTJ48K2Ls54ztB67sy8lP7kGrU6SDqykStK2/KA+Ffa8/4J3rIcRlHHcmbFCkOB lACBJNRv92pOB5i0N1lg6uf4Vt2hKOzh3vHMHUIAp13jD0gkGPt3EB0B1qXoRsbLQMyF B4hIe4IghQMBoxDh3hXNueItLdw6Fb+yxFsZ2H3TUGWx7dysxHf25OaNc9xazzyQ0W/9 ehow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=+lnXOruvwPuxAjkIojj7o4yQ5aFq/OmvzZbaJBwTWHI=; b=ld3g2hOEx4ntyCTWyDMUYGCkMWT+WKt1kA1L3pYowCIb+Q2RsFAK2FmiG3cPl/r/VP mKLwW8uZeKDZnhrbt5ZpK0WKi+/ElZsZ9okPWuxua20NQ6uZl2Jf3NuF8nLbSnaxd5Uj 1IBOSyqewNUYpgZQ/0TPD4CpVUae8zENh/ftnOiOKOZ25yfckeHqboHYyiKWN/bXz3tA diJH8r0T4qczRQNbgtfLBcT7mXSM6ivmEPiwZ2zNd/WTkMYJaBdGn2WDOcPuawWFzg+Z hljlWTLtHSjxZVBHctx/FHrJcBoxyGNpxJ7NKjrKCoDhSl215QyFdcYeAqO+Gk1qDt2u 38+Q== X-Gm-Message-State: AOAM5306FQadtFaJWYrt0J7JJ/yfufDojeuGj5X189h94imTfSX1/S2D G31MS/zVM7udgdBelQlZc7ECuQyBgdY= X-Google-Smtp-Source: ABdhPJyNuXppnabVqj7d9ZQ2+QlTwjxtPPlqmLeVjmVCa2hTDlWfTJW5plEXiufffA9L+CxmYIHu7A== X-Received: by 2002:adf:f701:: with SMTP id r1mr39481606wrp.341.1600450882691; Fri, 18 Sep 2020 10:41:22 -0700 (PDT) Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id a81sm6356179wmf.32.2020.09.18.10.41.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2020 10:41:22 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 3/6] hw/sd/sdcard: Do not use legal address '0' for INVALID_ADDRESS Date: Fri, 18 Sep 2020 19:41:14 +0200 Message-Id: <20200918174117.180057-4-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200918174117.180057-1-f4bug@amsat.org> References: <20200918174117.180057-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::441; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexander Bulekov , Markus Armbruster , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-block@nongnu.org, "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" As it is legal to WRITE/ERASE the address/block 0, change the value of this definition to an illegal address: UINT32_MAX. Signed-off-by: Philippe Mathieu-Daudé --- Cc: Dr. David Alan Gilbert Cc: Markus Armbruster Same problem I had with the pflash device last year... This break migration :( What is the best way to do this? --- hw/sd/sd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 30ae435d669..4c05152f189 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -53,7 +53,7 @@ #define SDSC_MAX_CAPACITY (2 * GiB) -#define INVALID_ADDRESS 0 +#define INVALID_ADDRESS UINT32_MAX typedef enum { sd_r0 = 0, /* no response */ @@ -666,8 +666,8 @@ static int sd_vmstate_pre_load(void *opaque) static const VMStateDescription sd_vmstate = { .name = "sd-card", - .version_id = 1, - .minimum_version_id = 1, + .version_id = 2, + .minimum_version_id = 2, .pre_load = sd_vmstate_pre_load, .fields = (VMStateField[]) { VMSTATE_UINT32(mode, SDState), From patchwork Fri Sep 18 17:41:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 305042 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E491C43464 for ; Fri, 18 Sep 2020 17:46:33 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1489E21707 for ; Fri, 18 Sep 2020 17:46:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZhZGCoBs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1489E21707 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:38432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kJKSu-00067I-2b for qemu-devel@archiver.kernel.org; Fri, 18 Sep 2020 13:46:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kJKO0-0002oR-C0; Fri, 18 Sep 2020 13:41:32 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:36859) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kJKNy-0000Gs-Qc; Fri, 18 Sep 2020 13:41:28 -0400 Received: by mail-wr1-x441.google.com with SMTP id z1so6461840wrt.3; Fri, 18 Sep 2020 10:41:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UJjk8ZR/erxbnrLQ53sw18LTpiI4+fnfSdMDknbc4K0=; b=ZhZGCoBsfn+UONcYcwvkGlZcMK6BlUdKqbm+mhCYd58+/Eh4d9YE4vY92e8ZuFUA9p PiVzVankmaErjjOayyHAsMXkeNXysviLJKTv8r3Ge9wxeHJfToT+LqV1yNxlWlWa8I2N 53zr5EhFIURU4kyDSn6hDMLLENamBoZBJzgdsq+JGm1BZBhcCcRKrlBVu9kJxlpYV+kp JK6Gd7hzv/+ZAniAekN4lr78Blr1y4vkYCIDZqG5pDHHhQUwpMnB2sqTI7tLeAc9Yg+H D25ug9cmDG7wlP+NUIqRvJ+wzjqUui5gdJW7uozVEprFL0/06YRSmb9/YwaC0YGjRjBE /2Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=UJjk8ZR/erxbnrLQ53sw18LTpiI4+fnfSdMDknbc4K0=; b=W1MWrTUegr23Em4m6jC35AIvEdLoudmHeeQQAoagh/2OpqTXOC/igymIZ3DiBgbFzK GV5fxllz6fswCGe3Lx7Bnwlwr0/4ToKDAqXgjel7YJOGWRfaA1EoTJFocMloz/HjHkC/ BERKHNilJTQaPPNrP5mc4hABZibS+rVtYQWn+uONp8gl5qL8Oekphake+cg5ZksScS/E 3zaQ2+5VjPLfLWHLZB8tf6WuCHTSqtB/Z58A3ebaGOu4bkUUNVLKNPf8jupqBn7N7bKi ty/AhEW/9yKF3BNIFu6G53Qaf6KWaVA5L3zgLvuYTopzle4qbXyQ4S4PN9xg8QKOuELd LEpQ== X-Gm-Message-State: AOAM5330ARiP37TCcqVOEuQN6metJ1ntlENfyVuP56buivLESwrITwnT V0u4Lr6I8S2VLP/rw/RB4P6MfzromY8= X-Google-Smtp-Source: ABdhPJznczTLAPC3R3Zkc7v6W/nZf8C8+osE5w7JYxVujdOV4cbj4HewTfP2XU27rIGGvsfaITRueQ== X-Received: by 2002:adf:a18c:: with SMTP id u12mr40631017wru.90.1600450885109; Fri, 18 Sep 2020 10:41:25 -0700 (PDT) Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id a81sm6356179wmf.32.2020.09.18.10.41.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2020 10:41:24 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 5/6] hw/sd/sdcard: Do not attempt to erase out of range addresses Date: Fri, 18 Sep 2020 19:41:16 +0200 Message-Id: <20200918174117.180057-6-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200918174117.180057-1-f4bug@amsat.org> References: <20200918174117.180057-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::441; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexander Bulekov , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" While the Spec v3 is not very clear, v6 states: If the host provides an out of range address as an argument to CMD32 or CMD33, the card shall indicate OUT_OF_RANGE error in R1 (ERX) for CMD38. If an address is out of range, do not attempt to erase it: return R1 with the error bit set. Buglink: https://bugs.launchpad.net/bugs/1895310 Reported-by: Alexander Bulekov Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index ee7b64023aa..4454d168e2f 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -766,6 +766,13 @@ static void sd_erase(SDState *sd) erase_end *= 512; } + if (sd->erase_start > sd->size || sd->erase_end > sd->size) { + sd->card_status |= OUT_OF_RANGE; + sd->erase_start = INVALID_ADDRESS; + sd->erase_end = INVALID_ADDRESS; + return; + } + erase_start = sd_addr_to_wpnum(erase_start); erase_end = sd_addr_to_wpnum(erase_end); sd->erase_start = INVALID_ADDRESS; From patchwork Fri Sep 18 17:41:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 273373 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CE1AC43463 for ; Fri, 18 Sep 2020 17:50:05 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AFC5D21707 for ; Fri, 18 Sep 2020 17:50:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="J5DP95l9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AFC5D21707 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46452 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kJKWJ-0001Aa-LI for qemu-devel@archiver.kernel.org; Fri, 18 Sep 2020 13:50:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kJKO2-0002oY-I5; Fri, 18 Sep 2020 13:41:32 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:44077) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kJKNz-0000H6-Sv; Fri, 18 Sep 2020 13:41:29 -0400 Received: by mail-wr1-x442.google.com with SMTP id s12so6432090wrw.11; Fri, 18 Sep 2020 10:41:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9kcH0QEir+isSyR2eHUJqmP++6hsLCDL3S99R+ttmDk=; b=J5DP95l9Z6YtITaZsBXMvA5zs9c6XNvkGG9iYEiiO0+mGUcnYjU11RkaSVFCRrwanu aTIVZ69APuXvTddh+zKnmbmqS58NLRD4Jg02xJNDbOYLjHUU03jg7JgKQroTNrY4PRAj +1n5Iaaqdl2WSTFpmL330WBcUwABfObP2D2K+WbVeh8Gq8vhv1DalRYvNBph6b7VrYGA 2x4n12sStSAa18cyCbwnYmL625Sk0uDPHgH9Hs+xHSCl3W+8lgFnKi9QmvdCJ5ulPNRg soY8qdzX4q75f2pMgY4W4DDKeW2FuefX2ScgQKbX+MXpipU4ukn5/1TnSZFPY7AixTuf k7SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=9kcH0QEir+isSyR2eHUJqmP++6hsLCDL3S99R+ttmDk=; b=Fu+Jp8pxzcQDIG1jbPoInRJb2hwd7YUWr4LSMRydQSZKsxYEozIglfGC3Z2OSPDHtT 4h54VHQkKkya+2sVbDzfDk9/YS44vV9LcED+gUdppcgMo/tPc+4NYGMHt/YRVUJV6D/G k6yQuYKrnuNS4kZR7bz3IXZqm+uRMBT40qbwaFHRSxNq9G82pBtYRjCMwhi3C/hWlu9K DEq5jZbRspaERe317BWG/zu6PzB41EIGNoi6yCMGp+41iskjalMCQhwDIPrCXHCwM04Z fl/941EhHUpTUa9qI5r0HOhWOWXrblvS+kc1x/5xEmhbbuOvFNlevKGJoan+qu6pkdNS GlYw== X-Gm-Message-State: AOAM5338AgOvMQUPLnAAQ+E7NqCOewe5eB0SCKklPyhXZWty6c54C1kf IxCAmVwBoUljxu+0FOaYKIOXvGnsuKA= X-Google-Smtp-Source: ABdhPJyMeIFAEVZTdOzB0Pw8v/FaiviAtUokePHmYKA14Cy0LXKynCoXlxQ0mOM+17jsj/hxbXpcqg== X-Received: by 2002:adf:f04c:: with SMTP id t12mr39660598wro.121.1600450886130; Fri, 18 Sep 2020 10:41:26 -0700 (PDT) Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id a81sm6356179wmf.32.2020.09.18.10.41.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2020 10:41:25 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 6/6] hw/sd/sdcard: Assert if accessing an illegal group Date: Fri, 18 Sep 2020 19:41:17 +0200 Message-Id: <20200918174117.180057-7-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200918174117.180057-1-f4bug@amsat.org> References: <20200918174117.180057-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::442; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexander Bulekov , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We can not have more group than 'wpgrps_size'. Assert if we are accessing a group above this limit. Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 4454d168e2f..c3febed2434 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -780,6 +780,7 @@ static void sd_erase(SDState *sd) sd->csd[14] |= 0x40; for (i = erase_start; i <= erase_end; i++) { + assert(i < sd->wpgrps_size); if (test_bit(i, sd->wp_groups)) { sd->card_status |= WP_ERASE_SKIP; } @@ -794,6 +795,7 @@ static uint32_t sd_wpbits(SDState *sd, uint64_t addr) wpnum = sd_addr_to_wpnum(addr); for (i = 0; i < 32; i++, wpnum++, addr += WPGROUP_SIZE) { + assert(wpnum < sd->wpgrps_size); if (addr < sd->size && test_bit(wpnum, sd->wp_groups)) { ret |= (1 << i); }