From patchwork Fri Jan 24 15:45:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13949659 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 EBBEEC02181 for ; Fri, 24 Jan 2025 15:53:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbLzA-0007KO-0C; Fri, 24 Jan 2025 10:52:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbLz6-0007KB-7y for qemu-devel@nongnu.org; Fri, 24 Jan 2025 10:52:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbLz3-0006ms-TC for qemu-devel@nongnu.org; Fri, 24 Jan 2025 10:52:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737733956; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CP+BeYR5Gl//cccFzIG3OGb6LhFJghy4FZ9u7PGcy6o=; b=fGXhv694X9pw1kcBbcz9CQeQa7MFdDylh4WNuOnhuiZx5D5q3nKr0GltTLAZRSsgMRgHyX ax45drNmD7NhEvv4nCkfRKig6pjfzpn6v4DpZ107K9GZkUjrpWOdVYQlpuU2iBLi0nLLQj 42y3q0r0xSCHgCCaVXRjXpIBCQPsBfI= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-423-wYw4iC4eOa66AgypCYPfJQ-1; Fri, 24 Jan 2025 10:52:32 -0500 X-MC-Unique: wYw4iC4eOa66AgypCYPfJQ-1 X-Mimecast-MFC-AGG-ID: wYw4iC4eOa66AgypCYPfJQ Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5dc0de54194so2044465a12.0 for ; Fri, 24 Jan 2025 07:52:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737733911; x=1738338711; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CP+BeYR5Gl//cccFzIG3OGb6LhFJghy4FZ9u7PGcy6o=; b=lvxsO0Ocy8FyoqXevc0Tmyn2BCdRH9dLbrmrYN9okWb7mPZqar/iJxr0U5vdudgygr ByrhmFui6ZR6tiUB/owMDk1oIeQMku3IDWB7Ulp8Hl8Z3K10lUhC/c+/0czTMPtUkEY7 6fkIQkXIiiZdB43UbjfZKAb8ECnhrlAKUPWr4g5Gt7Vlhaz+bSRURFfmV2U6yJ+2tpkD /l9I0OBBqoMU6QngxUK0q7kRlzMQ/Et/g/DsuO5szb5vanOJQzR+166GOLfZBnARabxI g1JEDLWmoEW1+HEy8mAQDsOZrl+jnvbIOaUpd0Pfqs62KoBjtg3Eq6c/E/4XVvVBplMm Opjg== X-Gm-Message-State: AOJu0YxRTuMosITan1UMGG9TfZ82ul6x3S+iePovnidqXb7bu5iUayzH q3/fFOsLd17FzX2NH3Vs3u+b0D/k9/zT1DBLcY/oYnbriuezduqceGdRICxVG3WeNIE126QbrRk 5CpjGpdt931Jq8SlF02j02kKqgxw1lSjIPpCGTj9suotcvStdoNmh2c/sHxNfm1WlEHeD6RsEVj k90nyNTgPye/grCqnaMOHYH0o7wPg4p/0LC8GAFQ== X-Gm-Gg: ASbGnctkqMkrZ/Bi7aI3H1BOmA+ByvfFMkG/dqdlEP/YdEC3hGdDvjgFAEPWIcX2t/9 bydmC5im9CaChTaxA6pfp/gO6/ThRzP5F9tpcBlOOVEpjSHCq4i0ulphLCqvQ0jY18HcU62Rqla MPm5qr5uaOalxKQbGquIoIWSmZaN3XjJlU5DuuvLeJFgbeucOOVYFS7fRrckUfDupmb5E7CXHmj CyV9WDdvvF48+SJm47cQowlUWN0FEZ3KJwYDxFPQdwDmw9A7ZLXsV9LYXRTC1Ls/h/ozLl+RAa9 GNmJ2SYmTE0nope2zH9vwFipjR6aHoxQKlTWQFd9DuHpMQJUXDgnXNc= X-Received: by 2002:a05:6000:d09:b0:38a:88d0:1c9c with SMTP id ffacd0b85a97d-38c22275430mr6769690f8f.17.1737733538726; Fri, 24 Jan 2025 07:45:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IFRqrgRX5kyR6AO0c7Kkk5lCFZNfbAShaldGSh5LDUN0/EB7e75pK3yNZku5RyXD3Krprce2g== X-Received: by 2002:a05:6000:d09:b0:38a:88d0:1c9c with SMTP id ffacd0b85a97d-38c22275430mr6769658f8f.17.1737733538321; Fri, 24 Jan 2025 07:45:38 -0800 (PST) Received: from localhost (p200300cbc719e000ca2c77c5de7dce89.dip0.t-ipconnect.de. [2003:cb:c719:e000:ca2c:77c5:de7d:ce89]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38c2a188689sm3057609f8f.48.2025.01.24.07.45.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Jan 2025 07:45:37 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Peter Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Alex Williamson , Eduardo Habkost , Marcel Apfelbaum , Elena Ufimtseva , Jagannathan Raman , "Dr. David Alan Gilbert" , Stefan Zabka Subject: [PATCH v2 1/7] physmem: factor out memory_region_is_ram_device() check in memory_access_is_direct() Date: Fri, 24 Jan 2025 16:45:26 +0100 Message-ID: <20250124154533.3534250-2-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250124154533.3534250-1-david@redhat.com> References: <20250124154533.3534250-1-david@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org As documented in commit 4a2e242bbb306 ("memory: Don't use memcpy for ram_device regions"), we disallow direct access to RAM DEVICE regions. Let's make this clearer to prepare for further changes. Note that romd regions will never be RAM DEVICE at the same time. Signed-off-by: David Hildenbrand --- include/exec/memory.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 3ee1901b52..7931aba2ea 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2987,12 +2987,19 @@ bool prepare_mmio_access(MemoryRegion *mr); static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) { + /* + * RAM DEVICE regions can be accessed directly using memcpy, but it might + * be MMIO and access using mempy can be wrong (e.g., using instructions not + * intended for MMIO access). So we treat this as IO. + */ + if (memory_region_is_ram_device(mr)) { + return false; + } if (is_write) { return memory_region_is_ram(mr) && !mr->readonly && - !mr->rom_device && !memory_region_is_ram_device(mr); + !mr->rom_device; } else { - return (memory_region_is_ram(mr) && !memory_region_is_ram_device(mr)) || - memory_region_is_romd(mr); + return memory_region_is_ram(mr) || memory_region_is_romd(mr); } } From patchwork Fri Jan 24 15:45:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13949764 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 B3ECAC02181 for ; Fri, 24 Jan 2025 16:55:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbMx5-0007n3-S6; Fri, 24 Jan 2025 11:54:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbMx0-0007dU-C7 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 11:54:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbMwy-0002c1-Ey for qemu-devel@nongnu.org; Fri, 24 Jan 2025 11:54:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737737669; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3ePR9BfsmNf8AyNCl2IDFJ8EDqHaAP0dpO83jGHFUug=; b=Iw06NtcaAJU5yyQvuTe4c6y7p9FrUv8GP77uijNgLYtkIdXTEOlY8lyev1f4xB9ozUIu/N qA1JZHPP7E65AGYivRsvxBi+wm+3k4STewQEItVwwMCoi6C5XbS6PfH1s8RquQzUlG0iCv BlEVUJrLbRwLGvYrFdSz4QExqA5t51U= 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.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-403-7KvTn-m5OSqCBhTkXAIXaA-1; Fri, 24 Jan 2025 11:54:28 -0500 X-MC-Unique: 7KvTn-m5OSqCBhTkXAIXaA-1 X-Mimecast-MFC-AGG-ID: 7KvTn-m5OSqCBhTkXAIXaA Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4361efc9d1fso18498795e9.2 for ; Fri, 24 Jan 2025 08:54:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737737667; x=1738342467; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3ePR9BfsmNf8AyNCl2IDFJ8EDqHaAP0dpO83jGHFUug=; b=gj376MFYtV7KZdeaN+5Tk7ArwTJSnwmXjUdYiNoE211tGOChEWQOpCbNTAfejBkpoi m00AtIJwfcqiDb6GaQptywCUYJk/B7/lbo3NtFGD9bOfYTIaxB5Nyn0frYcsXGtGlrC+ R7Fcf40Deyd7rfxJTnlIi0IqktSpcNjt5nj1/8+Pb9Hxi+FxNY3kfY9IdvqA9GT9/p91 nimNjQ/L7gGAXfcxOHBlYddBDWawXsuqbCIkiiYGO+txQ9rtJXdnrgFVwjnUXFarbas1 5G85OxbUJMVnXohQYZAq8eU/iOYAXAv4oURL9JOG77RZ0FNdF+t3DYeIE89/YKARUB2+ Qw0g== X-Gm-Message-State: AOJu0YwEkGaYCiebJ55bXF4qN/JECN1VQRY2wslko9g0M//yuLX82ZPV Tkpzh1Q1pQMY3gSTfzgSsS0e31LIN2tSZRDa4sJZTEU07/1CSe6MkRH28N7WDF7tKjFRw6MO2Lz sqbwnX/lHypMQaeOPVKch7CYj6pIG5v9z8K9tK7U+W7P0UYcCoccWPT3WTJFXq2nROXyOMIwIW+ sj3AqPEAAy3IxXeIFCMKQf39kpjMgF+HPh3436kg== X-Gm-Gg: ASbGncsLddl30vupxagIuJU5KElk6/aHPE46d5X2DXOjnexGvvWXg6ugRGhFZO1H8lI Zs5HAxVBgG1ewDf9w+iMN6guJl+4CuGAEbsW4q8oDVp5desGW5mFhcNvtVkGWyvg8MTDbNcoGeX xaX4xw4fBpx6lW8FO0G4LwD/4IWHjlogirvl6FOjpeabVlIyaLp7ez9AVDhIo/+Qp5VJDcsXNME CdW1CdW1q9ReMkd66dUOdN2hHdqXyHskeY8N3W2pjMz4YdLGhuoio8XE4EFHsGMkV0+R1dFPTig HWGW36q7llkdhQuG4fgy2xrGGRNV1Uoz6Pjl2YINSQHSkuZA75Lup2k= X-Received: by 2002:a05:600c:3b27:b0:434:fd15:3ac9 with SMTP id 5b1f17b1804b1-43891438051mr272045895e9.22.1737733541267; Fri, 24 Jan 2025 07:45:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IHX+bF1jsoWfK3OOfQ+wEsvfKmRDf/T/plhchDfJQvWcdh9dkSk9uw/jkaH7TgCWS+5ru9R8Q== X-Received: by 2002:a05:600c:3b27:b0:434:fd15:3ac9 with SMTP id 5b1f17b1804b1-43891438051mr272045555e9.22.1737733540821; Fri, 24 Jan 2025 07:45:40 -0800 (PST) Received: from localhost (p200300cbc719e000ca2c77c5de7dce89.dip0.t-ipconnect.de. [2003:cb:c719:e000:ca2c:77c5:de7d:ce89]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38c2a1764e9sm3070240f8f.17.2025.01.24.07.45.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Jan 2025 07:45:39 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Peter Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Alex Williamson , Eduardo Habkost , Marcel Apfelbaum , Elena Ufimtseva , Jagannathan Raman , "Dr. David Alan Gilbert" , Stefan Zabka Subject: [PATCH v2 2/7] physmem: factor out RAM/ROMD check in memory_access_is_direct() Date: Fri, 24 Jan 2025 16:45:27 +0100 Message-ID: <20250124154533.3534250-3-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250124154533.3534250-1-david@redhat.com> References: <20250124154533.3534250-1-david@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Let's factor more of the generic "is this directly accessible" check, independent of the "write" condition out. Note that the "!mr->rom_device" check in the write case essentially disallows the memory_region_is_romd() condition again. Further note that RAM DEVICE regions are also RAM regions, so we can check for RAM+ROMD first. This is a preparation for further changes. Signed-off-by: David Hildenbrand --- include/exec/memory.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 7931aba2ea..086dec5086 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2987,6 +2987,10 @@ bool prepare_mmio_access(MemoryRegion *mr); static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) { + /* ROM DEVICE regions only allow direct access if in ROMD mode. */ + if (!memory_region_is_ram(mr) && !memory_region_is_romd(mr)) { + return false; + } /* * RAM DEVICE regions can be accessed directly using memcpy, but it might * be MMIO and access using mempy can be wrong (e.g., using instructions not @@ -2996,11 +3000,9 @@ static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) return false; } if (is_write) { - return memory_region_is_ram(mr) && !mr->readonly && - !mr->rom_device; - } else { - return memory_region_is_ram(mr) || memory_region_is_romd(mr); + return !mr->readonly && !mr->rom_device; } + return true; } /** From patchwork Fri Jan 24 15:45:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13949661 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 54C94C0218B for ; Fri, 24 Jan 2025 16:02:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbM7S-0000e6-AH; Fri, 24 Jan 2025 11:01:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbM7Q-0000do-D4 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 11:01:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbM7O-00087x-UY for qemu-devel@nongnu.org; Fri, 24 Jan 2025 11:01:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737734473; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zSzhRdn4C5TQknUumN+J2fY4iQC6DedwUvkKqDEpUYM=; b=Y7c0DVPZ/O6im4vbjY6Jk0knMoppYexQM0a2i9rkdWJYhwl7sppPcTtbOnnrxdKlCmtjYI C588xLmKHALt+i05Vyujh1HPTsYG6Kc7yyArfuIoVSEwLjXcOQw6eafH4cw5PMceVhG7OK SK4bc4B80HDGQV1qvoHeSva/tT4C4cQ= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-127-anVxmih_N7KiM3qXq8QP3g-1; Fri, 24 Jan 2025 10:45:46 -0500 X-MC-Unique: anVxmih_N7KiM3qXq8QP3g-1 X-Mimecast-MFC-AGG-ID: anVxmih_N7KiM3qXq8QP3g Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43646b453bcso11101485e9.3 for ; Fri, 24 Jan 2025 07:45:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737733544; x=1738338344; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zSzhRdn4C5TQknUumN+J2fY4iQC6DedwUvkKqDEpUYM=; b=ejb/x1NekakxQ+sakRjWVTHZYz5c0sE71ADeKaNLt0GMnRAeo49cSg+AOsoL2qmos8 /Wn5aMJzXzWJLbKM6R73ukx19sdxFnNvKCCAUntSEmeqCazoGV5Xl/5Ok3TK7PrHohjz z3HpfBIW7X02+bWUbdVzqMEKIAnwfrRX8+aUgeS2DDA/CW3UeIYsY2mQUv8D/HCtsoRU Ot0RjSv3UCyPFOYuUMzdmmIiIX9rhrrQmtHKQc5Eim/tkJb3MU31jgZ5I9t2GzyxWfju MPWFvpqrVgaRX+YTdcWY8V0/olQfDl39885pPpijzut2mCaMcHsez81Xo/xzngw8cuAe w8Rg== X-Gm-Message-State: AOJu0YzGFGsDdCs8hdCPH5b5OkecwsNHxVNnacMKVkxipOf9rWe9cr6M GIYvWzcSYLYwGAv76zcyHTTbfbVVnscypLSi5Jui8kJPjpI2Fa15cB6Nx9ijjpTlWlLuJtDuR8b xvha+/BIMW0U5uGjKc0gYpHu/fBTT3nl/xd4RPzZOoh9hOYDpDwQE+2qQjl3ThYJOHT/KGWc8u6 YcTcmnWDwQ/XNLSGXHFnfgbYKGmwVn/I2Tldk6VQ== X-Gm-Gg: ASbGncvXPtVSY3wC3ky5jGbP7eQRL/jmgfg4SLjOSDjI6QVlrrO5HXMb31hca1Owpad ME8UvWkwMDhpsP8D5OIwqGHyUhwc0FCQtCNtFKVtsoXo6tRWa6Y7PV1y6l/wJFD5I/sEZQ2/q2Z Qqg+XNgds28baxiepj44xj/H0Fo/AGu3FsKkQoSANuos2mO5K0Fe8V7LCQ5iEZV+OgyB7uuIIkK dh3vWFLxhoTEMb0vRAnrFEkg3olZyr0rsyvwzAmyb9uyx3f7G3tFjZso7khG5V5l25axBo4DOEe xbpOHdNs7HFprlGtzvrYRDqCTu7RJSJMvYRHljn1bssGRZHfjwtR2kI= X-Received: by 2002:a05:600c:63d5:b0:438:a46b:1a6 with SMTP id 5b1f17b1804b1-438a46b0388mr226246645e9.18.1737733544518; Fri, 24 Jan 2025 07:45:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfev3uAK2i1mnL/YJSd4Cd8F5Oo5ZtUyZyr1LKsC5SY/9ZgQWrvz9QqAqq6os4oHkNx3IZ6g== X-Received: by 2002:a05:600c:63d5:b0:438:a46b:1a6 with SMTP id 5b1f17b1804b1-438a46b0388mr226246235e9.18.1737733544022; Fri, 24 Jan 2025 07:45:44 -0800 (PST) Received: from localhost (p200300cbc719e000ca2c77c5de7dce89.dip0.t-ipconnect.de. [2003:cb:c719:e000:ca2c:77c5:de7d:ce89]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-438bd4d2c0esm30382625e9.33.2025.01.24.07.45.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Jan 2025 07:45:42 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Peter Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Alex Williamson , Eduardo Habkost , Marcel Apfelbaum , Elena Ufimtseva , Jagannathan Raman , "Dr. David Alan Gilbert" , Stefan Zabka Subject: [PATCH v2 3/7] physmem: factor out direct access check into memory_region_supports_direct_access() Date: Fri, 24 Jan 2025 16:45:28 +0100 Message-ID: <20250124154533.3534250-4-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250124154533.3534250-1-david@redhat.com> References: <20250124154533.3534250-1-david@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Let's factor the complete "directly accessible" check independent of the "write" condition out so we can reuse it next. We can now split up the checks RAM and ROMD check, so we really only check for RAM DEVICE in case of RAM -- ROM DEVICE is neither RAM not RAM DEVICE. Signed-off-by: David Hildenbrand --- include/exec/memory.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 086dec5086..3b4449e847 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2985,10 +2985,13 @@ MemTxResult address_space_write_cached_slow(MemoryRegionCache *cache, int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr); bool prepare_mmio_access(MemoryRegion *mr); -static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) +static inline bool memory_region_supports_direct_access(MemoryRegion *mr) { /* ROM DEVICE regions only allow direct access if in ROMD mode. */ - if (!memory_region_is_ram(mr) && !memory_region_is_romd(mr)) { + if (memory_region_is_romd(mr)) { + return true; + } + if (!memory_region_is_ram(mr)) { return false; } /* @@ -2996,7 +2999,12 @@ static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) * be MMIO and access using mempy can be wrong (e.g., using instructions not * intended for MMIO access). So we treat this as IO. */ - if (memory_region_is_ram_device(mr)) { + return !memory_region_is_ram_device(mr); +} + +static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) +{ + if (!memory_region_supports_direct_access(mr)) { return false; } if (is_write) { From patchwork Fri Jan 24 15:45:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13949665 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 7CBE1C02181 for ; Fri, 24 Jan 2025 16:27:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbMWm-0002NU-9v; Fri, 24 Jan 2025 11:27:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbMWk-0002N8-Fe for qemu-devel@nongnu.org; Fri, 24 Jan 2025 11:27:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbMWe-0005Dy-FI for qemu-devel@nongnu.org; Fri, 24 Jan 2025 11:27:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737736039; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TcYXbuttJvyTYCdS1jYY2P3DyP6WKZ98vnviI1IyLBw=; b=CDFd7npQ0ZTT/ZU3UzxctqOVphsKpWBGJMvErLbQb88HvMdHnN8AX3g6ctLLw3U5N9vzyq 1ABZ+Hag5e+7+rhI+WLVSU1zAye+zuxsu09ZEIShANlam6mF5zPLOo30k5gkuVuSB+qRPR IAJt3NbXwiSXqis708TkriNEQKGW3IE= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-404-3z2bVknfMwmqMfSxRiMCQg-1; Fri, 24 Jan 2025 11:27:16 -0500 X-MC-Unique: 3z2bVknfMwmqMfSxRiMCQg-1 X-Mimecast-MFC-AGG-ID: 3z2bVknfMwmqMfSxRiMCQg Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-aa6732a1af5so277529566b.3 for ; Fri, 24 Jan 2025 08:27:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737735721; x=1738340521; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TcYXbuttJvyTYCdS1jYY2P3DyP6WKZ98vnviI1IyLBw=; b=H0ETnuprY9xR+mdxZcnOPL2QuYXopUzhZXmv69Cj0ehmcnylQ8elv4ukPJXRG16Fgm 3fOpuXsiiVL4QORxzwo4aNKQiMYZYjYGma8rI52CqZTxNnLKpu6FeB38GGUgLYFBoQwK QSJOJ88EoCyXedQ/4RBDFwhiJdw9pnBS2khuoucmKvBqV8LYCQ/2vuD4P/jVYfcR+xmo wJV+Y0NMa2UdZMWegPgbhv3lZCeeOYPMZYt8mklM2HxSK47HdkV791H8hm+3/ESpXwpH DaLUNpncKUrXrJJkzqyuscNqFcNJI8fOD0Q5gdwmly48AcPlzD1AMsfCuFPNPp1+h4pn Kbww== X-Gm-Message-State: AOJu0YylD2AtRXnmIiIC8KqK0yIW2jdFnaYR54In1Dnoc/oL8BvUDjMt /3heRtlF+ehk42awN+u2MbIWUkUrXyxjIsPbhvH2511Ba2vizM362acHm/dZPl+G7jeQyOs7Teo KDgXloeGM+akNiHWNlczxKO3ostPnOit1KPsSwjePB7Asf04MG6z7QaSFOK2pdcahaM3IyCmh7h ZdoNcfS41/qZ/3gBfM7+j5Vhsc4HnN1qHj4iMcnA== X-Gm-Gg: ASbGnctjJlXT7bXISiZiMuJ29xZXtWZ9HoD2c7RG5sGmc2Qbejw28LxwczuDQZPTKIS f04DnrINCuc5wBuW8z1w8hBLfCFCrXW9QPnfSeOTTZCZvMV/q8xIErAPuzuRXqDoMFXauixqweD d1mmejZNy2+ByboJ1gczA8c+JbBmGBkCpYWYyVveQGKQqQcYgFutXgr15l9YEoyvAehCylHiav9 L4ju3VlGGQxre2mrwHocUBrYJ0wKHd+V3d2EcphLIxaFF3ddL/F16LkMVbN+ahNzsu+PRFJGcsk oC2S6EfFnzhomquHJ5TpGD4aySmaPDLp5li9Q8H/xcsybdevKWJabQ0= X-Received: by 2002:a05:600c:4f8e:b0:438:ad4d:cf01 with SMTP id 5b1f17b1804b1-438ad4dd129mr200052585e9.7.1737733547704; Fri, 24 Jan 2025 07:45:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IGiXBr9NRQ9sJjlAXXbFZwrvB2NDC9H1nG8Bq2i09O5ZaQ+aitsafpmoJPw/XUeC/T0UwjIfQ== X-Received: by 2002:a05:600c:4f8e:b0:438:ad4d:cf01 with SMTP id 5b1f17b1804b1-438ad4dd129mr200052125e9.7.1737733547315; Fri, 24 Jan 2025 07:45:47 -0800 (PST) Received: from localhost (p200300cbc719e000ca2c77c5de7dce89.dip0.t-ipconnect.de. [2003:cb:c719:e000:ca2c:77c5:de7d:ce89]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-438bd4fa46esm30544735e9.1.2025.01.24.07.45.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Jan 2025 07:45:46 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Peter Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Alex Williamson , Eduardo Habkost , Marcel Apfelbaum , Elena Ufimtseva , Jagannathan Raman , "Dr. David Alan Gilbert" , Stefan Zabka Subject: [PATCH v2 4/7] physmem: disallow direct access to RAM DEVICE in address_space_write_rom() Date: Fri, 24 Jan 2025 16:45:29 +0100 Message-ID: <20250124154533.3534250-5-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250124154533.3534250-1-david@redhat.com> References: <20250124154533.3534250-1-david@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org As documented in commit 4a2e242bbb306 ("memory: Don't use memcpy for ram_device regions"), we disallow direct access to RAM DEVICE regions. This change implies that address_space_write_rom() and cpu_memory_rw_debug() won't be able to write to RAM DEVICE regions. It will also affect cpu_flush_icache_range(), but it's only used by hw/core/loader.c after writing to ROM, so it is expected to not apply here with RAM DEVICE. This fixes direct access to these regions where we don't want direct access. We'll extend cpu_memory_rw_debug() next to also be able to write to these (and IO) regions. This is a preparation for further changes. Cc: Alex Williamson Signed-off-by: David Hildenbrand --- system/physmem.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/system/physmem.c b/system/physmem.c index c76503aea8..2d4f8110e8 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -3029,8 +3029,7 @@ static inline MemTxResult address_space_write_rom_internal(AddressSpace *as, l = len; mr = address_space_translate(as, addr, &addr1, &l, true, attrs); - if (!(memory_region_is_ram(mr) || - memory_region_is_romd(mr))) { + if (!memory_region_supports_direct_access(mr)) { l = memory_access_size(mr, l, addr1); } else { /* ROM/RAM case */ From patchwork Fri Jan 24 15:45:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13949663 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 8297EC0218C for ; Fri, 24 Jan 2025 16:15:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbMKj-0002cI-9X; Fri, 24 Jan 2025 11:15:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbMKb-0002bl-OS for qemu-devel@nongnu.org; Fri, 24 Jan 2025 11:14:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbMKZ-0003O1-Px for qemu-devel@nongnu.org; Fri, 24 Jan 2025 11:14:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737735290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F7f1tc2RLZwpuRlPJgEUQZlg3M09OnkBiQJFOVKYZjo=; b=bO9kfNZdPYiNXeKIxReyova3Ub/CZ0xJsHz3FKLDrVY3alw6g34HmltEADJYMI3eeM2mO7 sm7dzkAUkp1SYwOWQwpb/QoqqRXbuTdVCeopJWdNo20/iY+yhVCaB+4LZqgZRou1wmJ+zR oK3tPuZXd1f+Vj40vaIggzRN1QAEcj4= 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.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-467-i8S0E-FpNq--NVWqiWhgzA-1; Fri, 24 Jan 2025 11:14:44 -0500 X-MC-Unique: i8S0E-FpNq--NVWqiWhgzA-1 X-Mimecast-MFC-AGG-ID: i8S0E-FpNq--NVWqiWhgzA Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43673af80a6so16061955e9.1 for ; Fri, 24 Jan 2025 08:14:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737734982; x=1738339782; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=F7f1tc2RLZwpuRlPJgEUQZlg3M09OnkBiQJFOVKYZjo=; b=ZzJKrBBQA2WPoUymK2dmzV9ozaIOcmY8F2/MXVIzwyFbuA5ZVwAhMCOvaoIQQYWBDd yiPx6/ICSO2E6u3u2YhaWEEb9UtuhSWhzcrr/bvZnWVQsdTLBuyOBADENabDw4779Nzn 07RkH02k816yJqmVvPgd1BH3FG6IzEGqthdE5X8Qoyr5EXeuq25r363HyMRefePHhyfV 1Zlzc+nfKf3a1n2ouS3MfjmI8fc6+kCBMIi/MMVcNIspCLl2PCfY9H2Agj2gTMvcFc0+ 4uckhvFyU3+6qOIQhn+f34kq7D0twXS2ijHfFdirFH5UtG8EuKwDhzHF6CPRuo4IsLQy MpKA== X-Gm-Message-State: AOJu0Yw0IVABpzAciIhzs+8fGcd8ZO3Y9Am09Ltm19D3n9EIryyPUJG8 C8KGbD+XeOGW9z3sK40Hd00fNRIJ/OkkVNho5H3SFogmNk7DqGITCydY76Y+smdfy97RJWTUDVJ YloNYQoJptl2yHC/76HMIKeAE3BQ5UFzbqdZaKhtqRMs6nlruspGLkR+0f2sm3xnhvbgm5mWdCi HjpGG+miwY8O5yEY8gYhY03ZjnWPf6WtU3tLkv2A== X-Gm-Gg: ASbGncszpVBxTuiDk88Ppo8x2uROGtjnMA1lUM/Yq/X1J+QlkzEJGtcPmfmgcRAzs+n MY9ABicY14gyLVFfAChIgu1mjzU7cvd2uevPmfUhDedLCkEtV8VR/sxQUKiB3gpQmjlXBLe2dOC oKsPWIVHpIAUy9EnABs+p1Iq5HljR4wu4/RX94tQDe+hvKBrQofeRMKOc/gEENHDT85P8QL4nFo sHYK1HDOmtE/i9aoUeaYmOSyf+OybWjqwaLCi3VKIrl8nSQYuYhRqSFcoE9p1epNGn7oYk0jO7M e/waAY6/VL2XUxaNcwrr1cz0XI5PhYrdpa4fDfgBZ43m4iSqiEH7Wpk= X-Received: by 2002:a05:600c:1c9d:b0:434:ffd7:6fd2 with SMTP id 5b1f17b1804b1-438913ca1ccmr279964225e9.7.1737733550988; Fri, 24 Jan 2025 07:45:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJC/3Q0TwiZdF42xv3QCiPhESIUDe2Hj+8cQ21pQULCDUoa5eYGiH8k9Xxew9m+CFzpIfpNQ== X-Received: by 2002:a05:600c:1c9d:b0:434:ffd7:6fd2 with SMTP id 5b1f17b1804b1-438913ca1ccmr279963855e9.7.1737733550551; Fri, 24 Jan 2025 07:45:50 -0800 (PST) Received: from localhost (p200300cbc719e000ca2c77c5de7dce89.dip0.t-ipconnect.de. [2003:cb:c719:e000:ca2c:77c5:de7d:ce89]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-438bd54c0f7sm29813815e9.28.2025.01.24.07.45.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Jan 2025 07:45:49 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Peter Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Alex Williamson , Eduardo Habkost , Marcel Apfelbaum , Elena Ufimtseva , Jagannathan Raman , "Dr. David Alan Gilbert" , Stefan Zabka Subject: [PATCH v2 5/7] memory: pass MemTxAttrs to memory_access_is_direct() Date: Fri, 24 Jan 2025 16:45:30 +0100 Message-ID: <20250124154533.3534250-6-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250124154533.3534250-1-david@redhat.com> References: <20250124154533.3534250-1-david@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We want to pass another flag that will be stored in MemTxAttrs. So pass MemTxAttrs directly. Signed-off-by: David Hildenbrand Reviewed-by: Philippe Mathieu-Daudé --- hw/core/loader.c | 2 +- hw/remote/vfio-user-obj.c | 2 +- include/exec/memory.h | 5 +++-- system/memory_ldst.c.inc | 18 +++++++++--------- system/physmem.c | 12 ++++++------ 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/hw/core/loader.c b/hw/core/loader.c index 4dfdb027ee..66de4da21f 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -144,7 +144,7 @@ ssize_t load_image_mr(const char *filename, MemoryRegion *mr) { ssize_t size; - if (!memory_access_is_direct(mr, false)) { + if (!memory_access_is_direct(mr, false, MEMTXATTRS_UNSPECIFIED)) { /* Can only load an image into RAM or ROM */ return -1; } diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c index 9e5ff6d87a..6e51a92856 100644 --- a/hw/remote/vfio-user-obj.c +++ b/hw/remote/vfio-user-obj.c @@ -358,7 +358,7 @@ static int vfu_object_mr_rw(MemoryRegion *mr, uint8_t *buf, hwaddr offset, int access_size; uint64_t val; - if (memory_access_is_direct(mr, is_write)) { + if (memory_access_is_direct(mr, is_write, MEMTXATTRS_UNSPECIFIED)) { /** * Some devices expose a PCI expansion ROM, which could be buffer * based as compared to other regions which are primarily based on diff --git a/include/exec/memory.h b/include/exec/memory.h index 3b4449e847..b3287518f0 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -3002,7 +3002,8 @@ static inline bool memory_region_supports_direct_access(MemoryRegion *mr) return !memory_region_is_ram_device(mr); } -static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) +static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write, + MemTxAttrs attrs) { if (!memory_region_supports_direct_access(mr)) { return false; @@ -3043,7 +3044,7 @@ MemTxResult address_space_read(AddressSpace *as, hwaddr addr, fv = address_space_to_flatview(as); l = len; mr = flatview_translate(fv, addr, &addr1, &l, false, attrs); - if (len == l && memory_access_is_direct(mr, false)) { + if (len == l && memory_access_is_direct(mr, false, attrs)) { ptr = qemu_map_ram_ptr(mr->ram_block, addr1); memcpy(buf, ptr, len); } else { diff --git a/system/memory_ldst.c.inc b/system/memory_ldst.c.inc index 0e6f3940a9..7f32d3d9ff 100644 --- a/system/memory_ldst.c.inc +++ b/system/memory_ldst.c.inc @@ -34,7 +34,7 @@ static inline uint32_t glue(address_space_ldl_internal, SUFFIX)(ARG1_DECL, RCU_READ_LOCK(); mr = TRANSLATE(addr, &addr1, &l, false, attrs); - if (l < 4 || !memory_access_is_direct(mr, false)) { + if (l < 4 || !memory_access_is_direct(mr, false, attrs)) { release_lock |= prepare_mmio_access(mr); /* I/O case */ @@ -103,7 +103,7 @@ static inline uint64_t glue(address_space_ldq_internal, SUFFIX)(ARG1_DECL, RCU_READ_LOCK(); mr = TRANSLATE(addr, &addr1, &l, false, attrs); - if (l < 8 || !memory_access_is_direct(mr, false)) { + if (l < 8 || !memory_access_is_direct(mr, false, attrs)) { release_lock |= prepare_mmio_access(mr); /* I/O case */ @@ -170,7 +170,7 @@ uint8_t glue(address_space_ldub, SUFFIX)(ARG1_DECL, RCU_READ_LOCK(); mr = TRANSLATE(addr, &addr1, &l, false, attrs); - if (!memory_access_is_direct(mr, false)) { + if (!memory_access_is_direct(mr, false, attrs)) { release_lock |= prepare_mmio_access(mr); /* I/O case */ @@ -207,7 +207,7 @@ static inline uint16_t glue(address_space_lduw_internal, SUFFIX)(ARG1_DECL, RCU_READ_LOCK(); mr = TRANSLATE(addr, &addr1, &l, false, attrs); - if (l < 2 || !memory_access_is_direct(mr, false)) { + if (l < 2 || !memory_access_is_direct(mr, false, attrs)) { release_lock |= prepare_mmio_access(mr); /* I/O case */ @@ -277,7 +277,7 @@ void glue(address_space_stl_notdirty, SUFFIX)(ARG1_DECL, RCU_READ_LOCK(); mr = TRANSLATE(addr, &addr1, &l, true, attrs); - if (l < 4 || !memory_access_is_direct(mr, true)) { + if (l < 4 || !memory_access_is_direct(mr, true, attrs)) { release_lock |= prepare_mmio_access(mr); r = memory_region_dispatch_write(mr, addr1, val, MO_32, attrs); @@ -314,7 +314,7 @@ static inline void glue(address_space_stl_internal, SUFFIX)(ARG1_DECL, RCU_READ_LOCK(); mr = TRANSLATE(addr, &addr1, &l, true, attrs); - if (l < 4 || !memory_access_is_direct(mr, true)) { + if (l < 4 || !memory_access_is_direct(mr, true, attrs)) { release_lock |= prepare_mmio_access(mr); r = memory_region_dispatch_write(mr, addr1, val, MO_32 | devend_memop(endian), attrs); @@ -377,7 +377,7 @@ void glue(address_space_stb, SUFFIX)(ARG1_DECL, RCU_READ_LOCK(); mr = TRANSLATE(addr, &addr1, &l, true, attrs); - if (!memory_access_is_direct(mr, true)) { + if (!memory_access_is_direct(mr, true, attrs)) { release_lock |= prepare_mmio_access(mr); r = memory_region_dispatch_write(mr, addr1, val, MO_8, attrs); } else { @@ -410,7 +410,7 @@ static inline void glue(address_space_stw_internal, SUFFIX)(ARG1_DECL, RCU_READ_LOCK(); mr = TRANSLATE(addr, &addr1, &l, true, attrs); - if (l < 2 || !memory_access_is_direct(mr, true)) { + if (l < 2 || !memory_access_is_direct(mr, true, attrs)) { release_lock |= prepare_mmio_access(mr); r = memory_region_dispatch_write(mr, addr1, val, MO_16 | devend_memop(endian), attrs); @@ -474,7 +474,7 @@ static void glue(address_space_stq_internal, SUFFIX)(ARG1_DECL, RCU_READ_LOCK(); mr = TRANSLATE(addr, &addr1, &l, true, attrs); - if (l < 8 || !memory_access_is_direct(mr, true)) { + if (l < 8 || !memory_access_is_direct(mr, true, attrs)) { release_lock |= prepare_mmio_access(mr); r = memory_region_dispatch_write(mr, addr1, val, MO_64 | devend_memop(endian), attrs); diff --git a/system/physmem.c b/system/physmem.c index 2d4f8110e8..52b20b8ae5 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -571,7 +571,7 @@ MemoryRegion *flatview_translate(FlatView *fv, hwaddr addr, hwaddr *xlat, is_write, true, &as, attrs); mr = section.mr; - if (xen_enabled() && memory_access_is_direct(mr, is_write)) { + if (xen_enabled() && memory_access_is_direct(mr, is_write, attrs)) { hwaddr page = ((addr & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE) - addr; *plen = MIN(page, *plen); } @@ -2761,7 +2761,7 @@ static MemTxResult flatview_write_continue_step(MemTxAttrs attrs, return MEMTX_ACCESS_ERROR; } - if (!memory_access_is_direct(mr, true)) { + if (!memory_access_is_direct(mr, true, attrs)) { uint64_t val; MemTxResult result; bool release_lock = prepare_mmio_access(mr); @@ -2857,7 +2857,7 @@ static MemTxResult flatview_read_continue_step(MemTxAttrs attrs, uint8_t *buf, return MEMTX_ACCESS_ERROR; } - if (!memory_access_is_direct(mr, false)) { + if (!memory_access_is_direct(mr, false, attrs)) { /* I/O case */ uint64_t val; MemTxResult result; @@ -3166,7 +3166,7 @@ static bool flatview_access_valid(FlatView *fv, hwaddr addr, hwaddr len, while (len > 0) { l = len; mr = flatview_translate(fv, addr, &xlat, &l, is_write, attrs); - if (!memory_access_is_direct(mr, is_write)) { + if (!memory_access_is_direct(mr, is_write, attrs)) { l = memory_access_size(mr, l, addr); if (!memory_region_access_valid(mr, xlat, l, is_write, attrs)) { return false; @@ -3246,7 +3246,7 @@ void *address_space_map(AddressSpace *as, fv = address_space_to_flatview(as); mr = flatview_translate(fv, addr, &xlat, &l, is_write, attrs); - if (!memory_access_is_direct(mr, is_write)) { + if (!memory_access_is_direct(mr, is_write, attrs)) { size_t used = qatomic_read(&as->bounce_buffer_size); for (;;) { hwaddr alloc = MIN(as->max_bounce_buffer_size - used, l); @@ -3379,7 +3379,7 @@ int64_t address_space_cache_init(MemoryRegionCache *cache, mr = cache->mrs.mr; memory_region_ref(mr); - if (memory_access_is_direct(mr, is_write)) { + if (memory_access_is_direct(mr, is_write, MEMTXATTRS_UNSPECIFIED)) { /* We don't care about the memory attributes here as we're only * doing this if we found actual RAM, which behaves the same * regardless of attributes; so UNSPECIFIED is fine. From patchwork Fri Jan 24 15:45:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13949656 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 4F556C02181 for ; Fri, 24 Jan 2025 15:47:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbLuD-0004q0-R3; Fri, 24 Jan 2025 10:47:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbLtl-0004bl-Lv for qemu-devel@nongnu.org; Fri, 24 Jan 2025 10:47:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbLtg-00061q-1n for qemu-devel@nongnu.org; Fri, 24 Jan 2025 10:47:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737733622; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tR/Bfe6dC3ViC24psGjFCtIkiPOyvc+/X6zxMElS99I=; b=PSizopPbt06b8B87eTgy8A6POqVFrQ3OerQlNUrTc781fiANAMS6DImfYbVz8JRIXnwj47 s0ICFCo/CgMJDaAhzavxrKdY5yBMt7Sly3q9vEBCzWvGlnpVlInxWY7vlOt27q3C7TtnfR RIp73Y0JrlHZOmEo5zM6oaoko8N/qgQ= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-359-QMGgxxLyNUuvWL-_vh4SEQ-1; Fri, 24 Jan 2025 10:45:54 -0500 X-MC-Unique: QMGgxxLyNUuvWL-_vh4SEQ-1 X-Mimecast-MFC-AGG-ID: QMGgxxLyNUuvWL-_vh4SEQ Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-38a684a096eso1073094f8f.2 for ; Fri, 24 Jan 2025 07:45:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737733553; x=1738338353; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tR/Bfe6dC3ViC24psGjFCtIkiPOyvc+/X6zxMElS99I=; b=pUr9lVXRf7NG9nPn8DIHDRw3YRcikpnBIW2zN6e/b1u5dERdkC6V/9OpXhKJu4XL3M 6MV0CGIwu4Bt4Z7pWTvdDI9GTBDqKkQ+etJ50JonfmsxAh92yJqCngTSjujqYrUzTO2x pWl/IPu8biKOFmcotDBhEnzaVNiRibNxBFVIHFtd3pZq3Rxla4EUjYjzfGQ4qQ9q6hXH mA2QbvdcZH+OmUly0XUSpHIssEhP1vaFLX/veWN68SJ+lwb5lrNcCxGpST8rzPyt2uB8 SJN1B8vx+wRffXHxISBVVKdM1oahdECVx6doGiON7j5nHqhTEhNX6UrKyRvfW9m7uIjv +TFQ== X-Gm-Message-State: AOJu0YzlXUoTsl1JzSKHQTqaG1LPQ6qHysCd6q8zlDFrmP/mNUp0aUeT LNzDp8cdenXjdvjUUZM9n8DxKeEop1UpMQj/u/65O6U6gnbSq3lJstNzLSOyyFzko/goRBdinnS URlndqpOh/oLXoDq1ARJxAjmjTlYHPom0a9mZ6svk1G06C9iLojcQ7QnPPCZYCG+GOQ5HUJBeTx K80ilXbLt/nR6Gaj0ua/d3COR24jhwB4vKt+0ONw== X-Gm-Gg: ASbGnctpBmnRihgbc97ah3djQlhijtK4Zy2GWfsJans+yyoBJpoXYkdCW73bJAbnFiz vYEho5sZsQel504wfBy2kVzJRzCS6u2u8Xlh2KRCzWuGtQwnzYoKmTTNLg8AfD9Vy7AWwjodM5B ESAz/DfAtEU0u8i8KiKl4CyssBoqFf/Ng+HcFSG1hqAGZOeIAMyzDrEN5OkGUiFKCOxKCdO5ypO z2OcpeWYI6M8ZqJ2irPCgBjxhX7s5PbYL2My23wIBTGzzC3rqjnDnJUELvg7wNzrRhzz/A4nvmO UeJukpgT9YCv7Wt1ZvA5oBKeUbzB0ntfpenG3MZgrAeXy129e9+WjnE= X-Received: by 2002:a5d:5512:0:b0:385:e8aa:2a4e with SMTP id ffacd0b85a97d-38bf57a1eb7mr21972208f8f.31.1737733553374; Fri, 24 Jan 2025 07:45:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IH8r58mr0bMdSqwIKv17vEXdb4niYrG3/6M8NhgVtYGosxG2wLMLUfyNYiJ/XcogVbU6gS8Gg== X-Received: by 2002:a5d:5512:0:b0:385:e8aa:2a4e with SMTP id ffacd0b85a97d-38bf57a1eb7mr21972182f8f.31.1737733552993; Fri, 24 Jan 2025 07:45:52 -0800 (PST) Received: from localhost (p200300cbc719e000ca2c77c5de7dce89.dip0.t-ipconnect.de. [2003:cb:c719:e000:ca2c:77c5:de7d:ce89]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38c2a1baf65sm3065085f8f.64.2025.01.24.07.45.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Jan 2025 07:45:52 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Peter Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Alex Williamson , Eduardo Habkost , Marcel Apfelbaum , Elena Ufimtseva , Jagannathan Raman , "Dr. David Alan Gilbert" , Stefan Zabka Subject: [PATCH v2 6/7] hmp: use cpu_get_phys_page_debug() in hmp_gva2gpa() Date: Fri, 24 Jan 2025 16:45:31 +0100 Message-ID: <20250124154533.3534250-7-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250124154533.3534250-1-david@redhat.com> References: <20250124154533.3534250-1-david@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We don't need the MemTxAttrs, so let's simply use the simpler function variant. Signed-off-by: David Hildenbrand Reviewed-by: Philippe Mathieu-Daudé --- monitor/hmp-cmds-target.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/monitor/hmp-cmds-target.c b/monitor/hmp-cmds-target.c index 0300faa8a2..0d2e9dce69 100644 --- a/monitor/hmp-cmds-target.c +++ b/monitor/hmp-cmds-target.c @@ -301,7 +301,6 @@ void hmp_gpa2hva(Monitor *mon, const QDict *qdict) void hmp_gva2gpa(Monitor *mon, const QDict *qdict) { target_ulong addr = qdict_get_int(qdict, "addr"); - MemTxAttrs attrs; CPUState *cs = mon_get_cpu(mon); hwaddr gpa; @@ -310,7 +309,7 @@ void hmp_gva2gpa(Monitor *mon, const QDict *qdict) return; } - gpa = cpu_get_phys_page_attrs_debug(cs, addr & TARGET_PAGE_MASK, &attrs); + gpa = cpu_get_phys_page_debug(cs, addr & TARGET_PAGE_MASK); if (gpa == -1) { monitor_printf(mon, "Unmapped\n"); } else { From patchwork Fri Jan 24 15:45:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13949666 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 8DDFEC0218B for ; Fri, 24 Jan 2025 16:28:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbMXo-00032H-Jx; Fri, 24 Jan 2025 11:28:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbMXi-00031H-IP for qemu-devel@nongnu.org; Fri, 24 Jan 2025 11:28:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbMXf-0005Ib-4x for qemu-devel@nongnu.org; Fri, 24 Jan 2025 11:28:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737736101; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Exu5epeTQjUXGqc6EvI9Ro49B7EhhPUJNuPMkX7VzoI=; b=gp4q76eYK7EchlRqqB3UG+TJyfWaTbnsLgMXbTXAJHUdl0mxCjZfmcysmaqhRwn+Q3Vu+3 +KIGe9UqoeVju57d+XGK2+TXohrQsgApoJKOJzZ9XSW75ydFvACHnF/ZJtPh25iEFYD1mf Sr8JCSX5zVnHQ5s69ldDeTShvQ4dNMI= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-160-Nyg78LUIP3CSKpp-2B1yig-1; Fri, 24 Jan 2025 11:28:18 -0500 X-MC-Unique: Nyg78LUIP3CSKpp-2B1yig-1 X-Mimecast-MFC-AGG-ID: Nyg78LUIP3CSKpp-2B1yig Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5dbaaed8aeeso2664244a12.1 for ; Fri, 24 Jan 2025 08:28:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737736094; x=1738340894; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Exu5epeTQjUXGqc6EvI9Ro49B7EhhPUJNuPMkX7VzoI=; b=a4PqyscTw6+eo8JBmr/17rKHB4KY6+uhRvE89RDApD70sbcULqOdaqi0LOM2lcxFiY uDkoLsLcZvWE3ehb2prbt8VigisSoN2/J7F85yRgY/yWHfGSlRkueqe+ypVEBJgIgXfV FHpERYxNA/6ITsANcZt3Vf7RM9mBQ1xUBcYG3RsVDc8eaEe3g6Ge6O7gqyGSs1kVoE7L SuYHCq5STKw7e4hGWtfzKG7iaLeIWTIVtjI7uSaGV+umeCw5SzxB4vKePSCDf/Cm8y3C 4N0DmOrroViVcG8q3eXvkaMmjt6URE/yjADVqaSU1GWqDR1zGQ3BKz8pp8009o8PImmQ TgHg== X-Gm-Message-State: AOJu0Yx/TH1LDzKLbi4lIAGdq8iD2+j9k6WZBv2P0GgpgyIylEa4JK0I PaBysBXlDybQA90l0/zjP2fKuANQetnZxmVkr45ZkiW8IL/DZ12KUx2G64rNUIjC8zH3gPzRNK0 vCctrtOOFCmIyJ62icdjBSPUIQX1JbPGoCYQHqZ8ixMMRr4KRf23Ci/+6sC6+oT2dO2hkzgAX25 QUj8SMt4CDDoND25Cd9HoSTrhqkw5YTeXz1Hk2xg== X-Gm-Gg: ASbGncsyGYxPTvocMrHZmtThk9vmYdewSG5caoSkbR/w4/hKPcE8R5XzqiNXRWb6pnQ cmLkvGfpU3iSh48xoCF3IltiWMSUW0NU+oH3pIYfosX9pTxHEKZr4+iZrL+EQZ7AJvvN26KbZj4 HolOcyrNwsW+CL2AKAzrXRflJI4ISWiPp3FMMnln9GL31r+f0OPHJoPvWZJC08oiVbw+G5cFko0 M/LDRjxS3hbZQjf3hu4WSW+QUvK30OaVpSdvVkJxAVS+G0NwVhK7fuzyJZKKfNnN/0yJA47QeTA taTokrbYDDik/t95thN7AmYQKaMUzVomuf0GeIgg+5ZhXdsxoqom57A= X-Received: by 2002:a05:600c:a03:b0:434:f7e3:bfbd with SMTP id 5b1f17b1804b1-4389142e8b5mr278514765e9.23.1737733555850; Fri, 24 Jan 2025 07:45:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IHHYcoJ39rm7gawbJbNWFUQOBEGFPj86Ylt2BpokstkF84V5QmwjWichPRMD70s0emuvSL/sA== X-Received: by 2002:a05:600c:a03:b0:434:f7e3:bfbd with SMTP id 5b1f17b1804b1-4389142e8b5mr278514425e9.23.1737733555431; Fri, 24 Jan 2025 07:45:55 -0800 (PST) Received: from localhost (p200300cbc719e000ca2c77c5de7dce89.dip0.t-ipconnect.de. [2003:cb:c719:e000:ca2c:77c5:de7d:ce89]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-438bd4fa57csm32121725e9.4.2025.01.24.07.45.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Jan 2025 07:45:54 -0800 (PST) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Peter Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Alex Williamson , Eduardo Habkost , Marcel Apfelbaum , Elena Ufimtseva , Jagannathan Raman , "Dr. David Alan Gilbert" , Stefan Zabka Subject: [PATCH v2 7/7] physmem: teach cpu_memory_rw_debug() to write to more memory regions Date: Fri, 24 Jan 2025 16:45:32 +0100 Message-ID: <20250124154533.3534250-8-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250124154533.3534250-1-david@redhat.com> References: <20250124154533.3534250-1-david@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=dhildenb@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Right now, we only allow for writing to memory regions that allow direct access using memcpy etc; all other writes are simply ignored. This implies that debugging guests will not work as expected when writing to MMIO device regions. Let's extend cpu_memory_rw_debug() to write to more memory regions, including MMIO device regions. Reshuffle the condition in memory_access_is_direct() to make it easier to read and add a comment. While this change implies that debug access can now also write to MMIO devices, we now are also permit ELF image loads and similar users of cpu_memory_rw_debug() to write to MMIO devices; currently we ignore these writes. Peter assumes [1] that there's probably a class of guest images, which will start writing junk (likely zeroes) into device model registers; we previously would silently ignore any such bogus ELF sections. Likely these images are of questionable correctness and this can be ignored. If ever a problem, we could make these cases use address_space_write_rom() instead, which is left unchanged for now. This patch is based on previous work by Stefan Zabka. [1] https://lore.kernel.org/all/CAFEAcA_2CEJKFyjvbwmpt=on=GgMVamQ5hiiVt+zUr6AY3X=Xg@mail.gmail.com/ Resolves: https://gitlab.com/qemu-project/qemu/-/issues/213 Signed-off-by: David Hildenbrand --- hw/core/cpu-system.c | 13 +++++++++---- include/exec/memattrs.h | 5 ++++- include/exec/memory.h | 3 ++- system/physmem.c | 9 ++------- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/hw/core/cpu-system.c b/hw/core/cpu-system.c index 6aae28a349..6e307c8959 100644 --- a/hw/core/cpu-system.c +++ b/hw/core/cpu-system.c @@ -51,13 +51,18 @@ hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr, MemTxAttrs *attrs) { CPUClass *cc = CPU_GET_CLASS(cpu); + hwaddr paddr; if (cc->sysemu_ops->get_phys_page_attrs_debug) { - return cc->sysemu_ops->get_phys_page_attrs_debug(cpu, addr, attrs); + paddr = cc->sysemu_ops->get_phys_page_attrs_debug(cpu, addr, attrs); + } else { + /* Fallback for CPUs which don't implement the _attrs_ hook */ + *attrs = MEMTXATTRS_UNSPECIFIED; + paddr = cc->sysemu_ops->get_phys_page_debug(cpu, addr); } - /* Fallback for CPUs which don't implement the _attrs_ hook */ - *attrs = MEMTXATTRS_UNSPECIFIED; - return cc->sysemu_ops->get_phys_page_debug(cpu, addr); + /* Indicate that this is a debug access. */ + attrs->debug = 1; + return paddr; } hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr) diff --git a/include/exec/memattrs.h b/include/exec/memattrs.h index e27c18f3dc..14e0edaa58 100644 --- a/include/exec/memattrs.h +++ b/include/exec/memattrs.h @@ -26,7 +26,8 @@ typedef struct MemTxAttrs { /* Bus masters which don't specify any attributes will get this * (via the MEMTXATTRS_UNSPECIFIED constant), so that we can * distinguish "all attributes deliberately clear" from - * "didn't specify" if necessary. + * "didn't specify" if necessary. "debug" can be set alongside + * "unspecified". */ unsigned int unspecified:1; /* @@ -50,6 +51,8 @@ typedef struct MemTxAttrs { * (see MEMTX_ACCESS_ERROR). */ unsigned int memory:1; + /* Debug access that can even write to ROM. */ + unsigned int debug:1; /* Requester ID (for MSI for example) */ unsigned int requester_id:16; diff --git a/include/exec/memory.h b/include/exec/memory.h index b3287518f0..2b9447ec8f 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -3008,7 +3008,8 @@ static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write, if (!memory_region_supports_direct_access(mr)) { return false; } - if (is_write) { + /* Debug access can write to ROM. */ + if (is_write && !attrs.debug) { return !mr->readonly && !mr->rom_device; } return true; diff --git a/system/physmem.c b/system/physmem.c index 52b20b8ae5..f153f57666 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -3572,13 +3572,8 @@ int cpu_memory_rw_debug(CPUState *cpu, vaddr addr, if (l > len) l = len; phys_addr += (addr & ~TARGET_PAGE_MASK); - if (is_write) { - res = address_space_write_rom(cpu->cpu_ases[asidx].as, phys_addr, - attrs, buf, l); - } else { - res = address_space_read(cpu->cpu_ases[asidx].as, phys_addr, - attrs, buf, l); - } + res = address_space_rw(cpu->cpu_ases[asidx].as, phys_addr, attrs, buf, + l, is_write); if (res != MEMTX_OK) { return -1; }