From patchwork Wed Dec 15 18:24:19 2021 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: 12679093 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id CA2FAC433F5 for ; Wed, 15 Dec 2021 18:55:12 +0000 (UTC) Received: from localhost ([::1]:47276 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mxZQl-0007Ax-Q4 for qemu-devel@archiver.kernel.org; Wed, 15 Dec 2021 13:55:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56492) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxYxD-0004kd-WD for qemu-devel@nongnu.org; Wed, 15 Dec 2021 13:24:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:27841) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxYxB-0007Ou-Sd for qemu-devel@nongnu.org; Wed, 15 Dec 2021 13:24:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639592677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7G1VF+PYn/+nnSsAzukj8f/eEEWiK0TuuEhDYLjNh0c=; b=Km7DPu+wwqho6VKpaWTKoLY8CyMP8HPZQLqmJU12BQpxXvJd9DZ1nxTpsFueJLE0OxmY77 VFMlEkV56ISdf5NSBiBzwb8t3QkHb2SrjRooxB0Ksc57BdPYDAqRpWDFaZXS1TpcDGbSgQ KJzjBgDauz764yZnEzvSrqThcWZBRJg= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-398-JQWKvfrRMiaGBX2Jei4tvg-1; Wed, 15 Dec 2021 13:24:36 -0500 X-MC-Unique: JQWKvfrRMiaGBX2Jei4tvg-1 Received: by mail-wm1-f70.google.com with SMTP id l4-20020a05600c1d0400b00332f47a0fa3so9353487wms.8 for ; Wed, 15 Dec 2021 10:24:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7G1VF+PYn/+nnSsAzukj8f/eEEWiK0TuuEhDYLjNh0c=; b=ubinczpF45h14vHAEQzpgSHd2CvMHRjNPR6+t1V1chR000wB1cR7OEpNvcgJ/eslzf FpVkCikuWu1Rp+xKjwXUeNlw+Mk18VE58tt5lNJ396LUWC7yusajKBireXOH3NAXrtMW Dq7oZ1qdIKFDwWK2j4D/KensOnCSwqOZ4GPA6dtd5ZsVEK4CahFdj5VVNmVpjues201B 1DaxtdlnoAfA4i0JWDdFSlKk26Ozd3oyWSO+iM+bd7ctvoVnE2C8e1aUu59OP+QAwbE7 ccEXvXj8m+XzTjj+D3nFLmZNrauef8Ru+P2jZ0GmDSPF8yhYTu7xHRRscSD00Qf7pq4h b/3w== X-Gm-Message-State: AOAM530o+u3w+yPsSaZvtboIgR3p8BmghMT0mnNuBZeiXEjYvVBx8YB5 u6Zop1IlJDRdvzUPIG7x2OFjcWVnUyIhm29r/vg+FkK9on3zHSXb3w1zKVrnkcb8kHsJr1yzErW 8F7wLgd5OPhJpwU/+TpY4kRtES620O0XzlICDYAwO2Fh7SFA+rKsJkfxM013vFzot X-Received: by 2002:a5d:6e04:: with SMTP id h4mr5527094wrz.127.1639592675051; Wed, 15 Dec 2021 10:24:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/6tQOC94ZVXRnSKKwJy/xHb6zXg14tepShevZlsuwcw/DDwFxXZmzwxaye+nN9pjDKGEubw== X-Received: by 2002:a5d:6e04:: with SMTP id h4mr5527064wrz.127.1639592674829; Wed, 15 Dec 2021 10:24:34 -0800 (PST) Received: from localhost.localdomain (174.red-83-50-185.dynamicip.rima-tde.net. [83.50.185.174]) by smtp.gmail.com with ESMTPSA id l7sm3197050wry.86.2021.12.15.10.24.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Dec 2021 10:24:34 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 1/3] hw/intc/arm_gicv3: Check for !MEMTX_OK instead of MEMTX_ERROR Date: Wed, 15 Dec 2021 19:24:19 +0100 Message-Id: <20211215182421.418374-2-philmd@redhat.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211215182421.418374-1-philmd@redhat.com> References: <20211215182421.418374-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.719, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , David Hildenbrand , Jason Wang , Li Qiang , Qiuhao Li , Peter Xu , Alexander Bulekov , qemu-arm@nongnu.org, Gerd Hoffmann , Stefan Hajnoczi , "Edgar E . Iglesias" , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Quoting Peter Maydell: "These MEMTX_* aren't from the memory transaction API functions; they're just being used by gicd_readl() and friends as a way to indicate a success/failure so that the actual MemoryRegionOps read/write fns like gicv3_dist_read() can log a guest error." We are going to introduce more MemTxResult bits, so it is safer to check for !MEMTX_OK rather than MEMTX_ERROR. Reviewed-by: Peter Xu Reviewed-by: David Hildenbrand Reviewed-by: Peter Maydell Reviewed-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daudé --- hw/intc/arm_gicv3_redist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/intc/arm_gicv3_redist.c b/hw/intc/arm_gicv3_redist.c index c8ff3eca085..99b11ca5eee 100644 --- a/hw/intc/arm_gicv3_redist.c +++ b/hw/intc/arm_gicv3_redist.c @@ -462,7 +462,7 @@ MemTxResult gicv3_redist_read(void *opaque, hwaddr offset, uint64_t *data, break; } - if (r == MEMTX_ERROR) { + if (r != MEMTX_OK) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid guest read at offset " TARGET_FMT_plx " size %u\n", __func__, offset, size); @@ -521,7 +521,7 @@ MemTxResult gicv3_redist_write(void *opaque, hwaddr offset, uint64_t data, break; } - if (r == MEMTX_ERROR) { + if (r != MEMTX_OK) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid guest write at offset " TARGET_FMT_plx " size %u\n", __func__, offset, size); From patchwork Wed Dec 15 18:24:20 2021 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: 12679117 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A0442C433EF for ; Wed, 15 Dec 2021 18:58:14 +0000 (UTC) Received: from localhost ([::1]:56922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mxZTh-0005VV-GN for qemu-devel@archiver.kernel.org; Wed, 15 Dec 2021 13:58:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxYxI-00054z-25 for qemu-devel@nongnu.org; Wed, 15 Dec 2021 13:24:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:43012) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxYxG-0007PZ-GH for qemu-devel@nongnu.org; Wed, 15 Dec 2021 13:24:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639592682; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4mzR8fzIq0zn1fqfmM14R0Bl8uzchpxL44PQBaxe0yI=; b=a9TrGpxaDYBP6q1Qdit7+YKpN5gKUl5qIW3H9w3gPD/7Dfdbj8QlAJJ51aUg6d/U6JMQos 3PM8qq40vovyj9M8zVI1k0Kh9rnal41Yn0V61w2rRL35P963hsfv0RUor8sxblzIPA6SVO SVYaOSHMilKTRFoobXct5cdVYFIxKxQ= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-319-GIwTXlE2PKKVAn-9-yJ19w-1; Wed, 15 Dec 2021 13:24:41 -0500 X-MC-Unique: GIwTXlE2PKKVAn-9-yJ19w-1 Received: by mail-wm1-f72.google.com with SMTP id l4-20020a05600c1d0400b00332f47a0fa3so9353601wms.8 for ; Wed, 15 Dec 2021 10:24:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4mzR8fzIq0zn1fqfmM14R0Bl8uzchpxL44PQBaxe0yI=; b=b84KkbnD2GmL/JdFMItaNDW30BvJ8am62kv479VfUarbRrtC/hkNMANgEU0pHklTAm ecTZ7XaFYHaFyGexmqTstcHne99XjevZJ1gGZ7dvixiHSwswbzisSJszn3D4AMDVdqJ0 sF80E/3YXzPtg8XHdglVnXDySHx2rGJs2XkVDQcnhOKiJVciN+DA6MbxHroumZ2OwrOO WAZsz4+qaMLJvCDhwqVNlKvqA5QD7IAgmTj2XdLPG5+E4rax1q+aNZJ/A/cW6soUhNsA R6tVEY9k4HrxnyhiPhermlvh30cCdys4RFUdMOuw1TyGRr7kZTYbOELdiYboNkiXEzq3 MyPw== X-Gm-Message-State: AOAM530a3AdRSOroovWwjJYn4rdgzHiCgQMkgUm46G1Kb0xJ9d0nB1SF I8SoSAWdKB6rqvJJBYIGEZqUxGBxAN/rX4bJkQrKFJMDSO4Cn3TbldsGCyJcZz8Ikm5rJz5QJyT EW+ZmBlDmPcA+n60kgPnTPnsCakkBkwmuqSiwhpc+mkgdCxnZ5YAoJt33VZLoT4lQ X-Received: by 2002:a05:600c:3489:: with SMTP id a9mr1268610wmq.120.1639592679631; Wed, 15 Dec 2021 10:24:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjDwwBzg4qM9VuIUo4SsY/rYgAnw8MhOpilDb7jMV/eZQPVAVJ9516Umrn+mKP4jElxhqajg== X-Received: by 2002:a05:600c:3489:: with SMTP id a9mr1268568wmq.120.1639592679356; Wed, 15 Dec 2021 10:24:39 -0800 (PST) Received: from localhost.localdomain (174.red-83-50-185.dynamicip.rima-tde.net. [83.50.185.174]) by smtp.gmail.com with ESMTPSA id 8sm3103664wrb.49.2021.12.15.10.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Dec 2021 10:24:39 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 2/3] softmmu/physmem: Simplify flatview_write and address_space_access_valid Date: Wed, 15 Dec 2021 19:24:20 +0100 Message-Id: <20211215182421.418374-3-philmd@redhat.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211215182421.418374-1-philmd@redhat.com> References: <20211215182421.418374-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.129.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.719, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , David Hildenbrand , Jason Wang , Li Qiang , Qiuhao Li , Peter Xu , Alexander Bulekov , qemu-arm@nongnu.org, Gerd Hoffmann , Stefan Hajnoczi , "Edgar E . Iglesias" , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Remove unuseful local 'result' variables. Reviewed-by: Peter Xu Reviewed-by: David Hildenbrand Reviewed-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daudé --- softmmu/physmem.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 007e7526f0a..6c97a20107a 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2815,14 +2815,11 @@ static MemTxResult flatview_write(FlatView *fv, hwaddr addr, MemTxAttrs attrs, hwaddr l; hwaddr addr1; MemoryRegion *mr; - MemTxResult result = MEMTX_OK; l = len; mr = flatview_translate(fv, addr, &addr1, &l, true, attrs); - result = flatview_write_continue(fv, addr, attrs, buf, len, - addr1, l, mr); - - return result; + return flatview_write_continue(fv, addr, attrs, buf, len, + addr1, l, mr); } /* Called within RCU critical section. */ @@ -3119,12 +3116,10 @@ bool address_space_access_valid(AddressSpace *as, hwaddr addr, MemTxAttrs attrs) { FlatView *fv; - bool result; RCU_READ_LOCK_GUARD(); fv = address_space_to_flatview(as); - result = flatview_access_valid(fv, addr, len, is_write, attrs); - return result; + return flatview_access_valid(fv, addr, len, is_write, attrs); } static hwaddr From patchwork Wed Dec 15 18:24:21 2021 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: 12679127 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E76E5C433F5 for ; Wed, 15 Dec 2021 19:23:41 +0000 (UTC) Received: from localhost ([::1]:48080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mxZsJ-0004gz-J7 for qemu-devel@archiver.kernel.org; Wed, 15 Dec 2021 14:23:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56556) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxYxN-0005V9-HL for qemu-devel@nongnu.org; Wed, 15 Dec 2021 13:24:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52255) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxYxL-0007Px-GT for qemu-devel@nongnu.org; Wed, 15 Dec 2021 13:24:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639592686; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qgbl1qGGn0Mrb86U52QIs0aG9NLVai4plfdZIwipvAo=; b=RvJkx0SoTa5lVAH1DN/FIHHKuF0gZpzSCkmSwHr/odn6HvObe+72Va7py9HefTfMf3k8Rq HMnaRzlGcAEy7eELrEnR9Q6bm6wQwt1dR3/e7jZtzFtQNYXdzxWShI4UUtayinCtNQ4oOy nmcVQZiG5W81KZinoSHU8xIQCJSl3VM= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-596-II3OYx6aNT-EF2KrURDWwQ-1; Wed, 15 Dec 2021 13:24:45 -0500 X-MC-Unique: II3OYx6aNT-EF2KrURDWwQ-1 Received: by mail-wm1-f70.google.com with SMTP id v23-20020a05600c215700b0034566adb612so1237874wml.0 for ; Wed, 15 Dec 2021 10:24:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Qgbl1qGGn0Mrb86U52QIs0aG9NLVai4plfdZIwipvAo=; b=r35fRCLjiIQmynrIjKz/yHxh9P5WZUn8SFMs7G+BlgKdClhUoSrt31bWdlG7E0AUPw H3fC3lbzrTBmIWjP6EmYl3h5LDtfYnv8yLxBlUK/mHo09WXFM6qhn/WHG3nCGKKsJEsU L7uFAA5upsyVoy/JDOlnWv4u1v9CKa3ZmIKciLBunJSl7uPBGDax9hO615Rg/uA6lRoo RyXqpznZCTsBboPEY1KU4LQQb6yOxTjVHBUamv1E0CKblBRGGObvnQ+A5n35bpwo+MUe LmLwEjhjlG//bTU6SXwcxpsk5805J1Cm/glouUGv7pJ1T8TubFGEPJ+61aqbuwzdcdi0 mYdQ== X-Gm-Message-State: AOAM530oVjO6XC8A+Su/41KqxfygwjN/6KN2Iap+YxDQN8JUJc2AUdV6 lNtxFVgsXTA9slCRYXukxAF8mtWUDfXoRKrw6FGgBUfy+B36e6gcedoiBdeezx4feSu3wcmjnCi dFbsRCzHgVLrwb60B+LLxm94TENA5CRUCYB4sK1krcutSm4iEvwbpewuRn/G2S9uz X-Received: by 2002:a1c:7714:: with SMTP id t20mr1239922wmi.139.1639592684257; Wed, 15 Dec 2021 10:24:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwpaabsCA78x06H1uYhXHm0o3inKjGufr9gQkFjF3/b1QFaIPlsGYfF0QkLkJlzYRwkOpJBzA== X-Received: by 2002:a1c:7714:: with SMTP id t20mr1239873wmi.139.1639592683929; Wed, 15 Dec 2021 10:24:43 -0800 (PST) Received: from localhost.localdomain (174.red-83-50-185.dynamicip.rima-tde.net. [83.50.185.174]) by smtp.gmail.com with ESMTPSA id o1sm3493282wri.100.2021.12.15.10.24.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Dec 2021 10:24:43 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH v3 3/3] softmmu/physmem: Introduce MemTxAttrs::memory field and MEMTX_BUS_ERROR Date: Wed, 15 Dec 2021 19:24:21 +0100 Message-Id: <20211215182421.418374-4-philmd@redhat.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211215182421.418374-1-philmd@redhat.com> References: <20211215182421.418374-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.719, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , David Hildenbrand , Jason Wang , Li Qiang , Qiuhao Li , Peter Xu , Alexander Bulekov , qemu-arm@nongnu.org, Gerd Hoffmann , Stefan Hajnoczi , "Edgar E . Iglesias" , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add the 'memory' bit to the memory attributes to restrict bus controller accesses to memories. Introduce flatview_access_allowed() to check bus permission before running any bus transaction. Have read/write accessors return MEMTX_BUS_ERROR if an access is restricted. There is no change for the default case where 'memory' is not set. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Reviewed-by: Stefan Hajnoczi --- include/exec/memattrs.h | 9 +++++++++ softmmu/physmem.c | 43 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/include/exec/memattrs.h b/include/exec/memattrs.h index 95f2d20d55b..f0063583ee2 100644 --- a/include/exec/memattrs.h +++ b/include/exec/memattrs.h @@ -35,6 +35,14 @@ typedef struct MemTxAttrs { unsigned int secure:1; /* Memory access is usermode (unprivileged) */ unsigned int user:1; + /* + * Bus interconnect and peripherals can access anything (memories, + * devices) by default. By setting the 'memory' bit, bus transaction + * are restricted to "normal" memories (per the AMBA documentation) + * versus devices. Access to devices will be logged and rejected + * (see MEMTX_BUS_ERROR). + */ + unsigned int memory:1; /* Requester ID (for MSI for example) */ unsigned int requester_id:16; /* Invert endianness for this page */ @@ -66,6 +74,7 @@ typedef struct MemTxAttrs { #define MEMTX_OK 0 #define MEMTX_ERROR (1U << 0) /* device returned an error */ #define MEMTX_DECODE_ERROR (1U << 1) /* nothing at that address */ +#define MEMTX_BUS_ERROR (1U << 2) /* bus returned an error */ typedef uint32_t MemTxResult; #endif diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 6c97a20107a..c03abcc0362 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2759,6 +2759,33 @@ static bool prepare_mmio_access(MemoryRegion *mr) return release_lock; } +/** + * flatview_access_allowed + * @mr: #MemoryRegion to be accessed + * @attrs: memory transaction attributes + * @addr: address within that memory region + * @len: the number of bytes to access + * + * Check if a memory transaction is allowed. + * + * Returns: true if transaction is allowed, false if denied. + */ +static inline bool flatview_access_allowed(MemoryRegion *mr, MemTxAttrs attrs, + hwaddr addr, hwaddr len) +{ + if (likely(!attrs.memory)) { + return true; + } + if (memory_region_is_ram(mr)) { + return true; + } + qemu_log_mask(LOG_GUEST_ERROR, + "Invalid access to non-RAM device at " + "addr 0x%" HWADDR_PRIX ", size %" HWADDR_PRIu ", " + "region '%s'\n", addr, len, memory_region_name(mr)); + return false; +} + /* Called within RCU critical section. */ static MemTxResult flatview_write_continue(FlatView *fv, hwaddr addr, MemTxAttrs attrs, @@ -2773,7 +2800,10 @@ static MemTxResult flatview_write_continue(FlatView *fv, hwaddr addr, const uint8_t *buf = ptr; for (;;) { - if (!memory_access_is_direct(mr, true)) { + if (!flatview_access_allowed(mr, attrs, addr1, l)) { + result |= MEMTX_BUS_ERROR; + /* Keep going. */ + } else if (!memory_access_is_direct(mr, true)) { release_lock |= prepare_mmio_access(mr); l = memory_access_size(mr, l, addr1); /* XXX: could force current_cpu to NULL to avoid @@ -2818,6 +2848,9 @@ static MemTxResult flatview_write(FlatView *fv, hwaddr addr, MemTxAttrs attrs, l = len; mr = flatview_translate(fv, addr, &addr1, &l, true, attrs); + if (!flatview_access_allowed(mr, attrs, addr, len)) { + return MEMTX_BUS_ERROR; + } return flatview_write_continue(fv, addr, attrs, buf, len, addr1, l, mr); } @@ -2836,7 +2869,10 @@ MemTxResult flatview_read_continue(FlatView *fv, hwaddr addr, fuzz_dma_read_cb(addr, len, mr); for (;;) { - if (!memory_access_is_direct(mr, false)) { + if (!flatview_access_allowed(mr, attrs, addr1, l)) { + result |= MEMTX_BUS_ERROR; + /* Keep going. */ + } else if (!memory_access_is_direct(mr, false)) { /* I/O case */ release_lock |= prepare_mmio_access(mr); l = memory_access_size(mr, l, addr1); @@ -2879,6 +2915,9 @@ static MemTxResult flatview_read(FlatView *fv, hwaddr addr, l = len; mr = flatview_translate(fv, addr, &addr1, &l, false, attrs); + if (!flatview_access_allowed(mr, attrs, addr, len)) { + return MEMTX_BUS_ERROR; + } return flatview_read_continue(fv, addr, attrs, buf, len, addr1, l, mr); }