From nobody Tue May 7 13:31:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591330736; cv=none; d=zohomail.com; s=zohoarc; b=h0zAQ8mmDbaobxC2Bckmb4tJiG2V1Hg/ADqB7v1wnvizFE7KTYlZ7HMqkjSoiGhQWiIQeIY0iOKA961nFL9Lt2g9uNNzprmJXSNRb3JrgMcTLSRA7Lq9y83bXdQEpyn1ONjYPb4xK9KdJRK2zyh6/rCJlNNe5w6PIU6MaOnhNwc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591330736; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=afqYJRs0BdUykWHYLxRC5+OCKgvwuuB1J/PoMsnkMLE=; b=hextU0iDlIsXYgPYDGtrsqE1parDk5OEzvhYVxl+fstxq1SI1BfQggJTNdKV2GBLKwEXMIs7wIHy8KJp6X5u60f4fsIKBKCJNLy5gOyWOD8ieW91Jn8ACRHPMKqbm+H2N996bUUm677/te05wzfz8SpD7OoIrQpm+e2Wjs1sQ/A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591330736233209.70575985461608; Thu, 4 Jun 2020 21:18:56 -0700 (PDT) Received: from localhost ([::1]:40804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jh3ol-0006P0-0D for importer@patchew.org; Fri, 05 Jun 2020 00:18:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39428) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jh3nX-00049g-L4 for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:39 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:33628) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jh3nW-0000hd-97 for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:39 -0400 Received: by mail-pj1-x1043.google.com with SMTP id b7so2858060pju.0 for ; Thu, 04 Jun 2020 21:17:37 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id h15sm5440902pgl.12.2020.06.04.21.17.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 21:17:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=afqYJRs0BdUykWHYLxRC5+OCKgvwuuB1J/PoMsnkMLE=; b=wIWshM2EpGYLAAiKmopR5JOwhnbU+IQ4C7bWf0uxoIXdg2ql5/sDM1P/2CKTNyOqeH 5whdNrOC3htm0ppzpk2UtRR6Y1dHlCT74NRaWWl1c3nqwgFr1G23kFa+dnV9SYdYWTjB XpGcuQIpLPphA1Fco4Pk8BJw17dtAd1vjIjp6I9vxyAyOSXkv+UoqCoZBWdAnTgKaa/z nYLUCUU3ZfMKNiZCTjqKTdPix6hQrMuW3P2pqtfm+ZtuvSypY2FDFmpcP+HMouSC0quD GXxOvJayZqW9TyKUY0E9RkUdw5W0wjTgpuwFrYcPtFVZbDTD7WPMQBMwPVEjixD+qfap fqqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=afqYJRs0BdUykWHYLxRC5+OCKgvwuuB1J/PoMsnkMLE=; b=NOvIRhJZ1DUhc4U4MMexE3Y1dOmkAEmfgKlnLM9Nm3iGH1lP/BNiawREcWdeDlT2ln 4353UgkZM5dwXlVPf35TvdS2Y0Q0Um6JtbAJa20RZy1zEErie4jKhx8X3UPLbBweboUp Ct9R4L6z6wFpVN/jiwKTlaimpi9mvT++ZRlxE0GVNJAmD62cPC/cBu3eNQOmKUl6W7AB FaILqEkQqnlnpiGawWF3Fv/J1rkQrgg/QPp9DpHeQyelfF4geglahUUwEU/4VJZ3cHWr CxyYP+8UfqGbYav6OwfIwkNlLPss04w55s/FZLmARuKGYd9y225Bq7rc5PEk1KPUXZ4V 7bZg== X-Gm-Message-State: AOAM5334ohkEpVkDN+r7sDj40X5uLt2yGAFbFfvHuK+3PziukcCcB1dP EMQ1XwVOQu5iyAV7h4jAj9kcpWYuRwc= X-Google-Smtp-Source: ABdhPJx4/yaP8MhRVKkw+hvtmKLS0OReHZ7PrDtVomzw66GwfD11zybexOQTX5+qafD9a892S7l6pg== X-Received: by 2002:a17:90a:2306:: with SMTP id f6mr752232pje.231.1591330656597; Thu, 04 Jun 2020 21:17:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 01/17] tcg: Introduce target-specific page data for user-only Date: Thu, 4 Jun 2020 21:17:17 -0700 Message-Id: <20200605041733.415188-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200605041733.415188-1-richard.henderson@linaro.org> References: <20200605041733.415188-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1043; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1043.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, qemu-arm@nongnu.org, steplong@quicinc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This data can be allocated by page_alloc_target_data() and released by page_set_flags(start, end, prot | PAGE_RESET). This data will be used to hold tag memory for AArch64 MTE. Signed-off-by: Richard Henderson --- include/exec/cpu-all.h | 20 ++++++++++++++------ accel/tcg/translate-all.c | 28 ++++++++++++++++++++++++++++ linux-user/mmap.c | 5 ++++- linux-user/syscall.c | 4 ++-- 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index 2bd023d692..e5f564fa1f 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -266,15 +266,21 @@ extern intptr_t qemu_host_page_mask; #define PAGE_EXEC 0x0004 #define PAGE_BITS (PAGE_READ | PAGE_WRITE | PAGE_EXEC) #define PAGE_VALID 0x0008 -/* original state of the write flag (used when tracking self-modifying - code */ +/* + * Original state of the write flag (used when tracking self-modifying cod= e) + */ #define PAGE_WRITE_ORG 0x0010 -/* Invalidate the TLB entry immediately, helpful for s390x - * Low-Address-Protection. Used with PAGE_WRITE in tlb_set_page_with_attrs= () */ -#define PAGE_WRITE_INV 0x0040 +/* + * Invalidate the TLB entry immediately, helpful for s390x + * Low-Address-Protection. Used with PAGE_WRITE in tlb_set_page_with_attrs= () + */ +#define PAGE_WRITE_INV 0x0020 +/* For use with page_set_flags: page is being replaced; target_data cleare= d. */ +#define PAGE_RESET 0x0040 + #if defined(CONFIG_BSD) && defined(CONFIG_USER_ONLY) /* FIXME: Code that sets/uses this is broken and needs to go away. */ -#define PAGE_RESERVED 0x0020 +#define PAGE_RESERVED 0x0100 #endif /* Target-specific bits that will be used via page_get_flags(). */ #define PAGE_TARGET_1 0x0080 @@ -289,6 +295,8 @@ int walk_memory_regions(void *, walk_memory_regions_fn); int page_get_flags(target_ulong address); void page_set_flags(target_ulong start, target_ulong end, int flags); int page_check_range(target_ulong start, target_ulong len, int flags); +void *page_get_target_data(target_ulong address); +void *page_alloc_target_data(target_ulong address, size_t size); #endif =20 CPUArchState *cpu_copy(CPUArchState *env); diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 42ce1dfcff..a65bc1d4c2 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -111,6 +111,7 @@ typedef struct PageDesc { unsigned int code_write_count; #else unsigned long flags; + void *target_data; #endif #ifndef CONFIG_USER_ONLY QemuSpin lock; @@ -2525,6 +2526,7 @@ int page_get_flags(target_ulong address) void page_set_flags(target_ulong start, target_ulong end, int flags) { target_ulong addr, len; + bool reset_target_data; =20 /* This function should never be called with addresses outside the guest address space. If this assert fires, it probably indicates @@ -2539,6 +2541,8 @@ void page_set_flags(target_ulong start, target_ulong = end, int flags) if (flags & PAGE_WRITE) { flags |=3D PAGE_WRITE_ORG; } + reset_target_data =3D !(flags & PAGE_VALID) || (flags & PAGE_RESET); + flags &=3D ~PAGE_RESET; =20 for (addr =3D start, len =3D end - start; len !=3D 0; @@ -2552,10 +2556,34 @@ void page_set_flags(target_ulong start, target_ulon= g end, int flags) p->first_tb) { tb_invalidate_phys_page(addr, 0); } + if (reset_target_data && p->target_data) { + g_free(p->target_data); + p->target_data =3D NULL; + } p->flags =3D flags; } } =20 +void *page_get_target_data(target_ulong address) +{ + PageDesc *p =3D page_find(address >> TARGET_PAGE_BITS); + return p ? p->target_data : NULL; +} + +void *page_alloc_target_data(target_ulong address, size_t size) +{ + PageDesc *p =3D page_find(address >> TARGET_PAGE_BITS); + void *ret =3D NULL; + + if (p) { + ret =3D p->target_data; + if (!ret && (p->flags & PAGE_VALID)) { + p->target_data =3D ret =3D g_malloc0(size); + } + } + return ret; +} + int page_check_range(target_ulong start, target_ulong len, int flags) { PageDesc *p; diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 40f03e3174..f9832609b0 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -599,6 +599,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t target_prot, } } the_end1: + page_flags |=3D PAGE_RESET; page_set_flags(start, start + len, page_flags); the_end: trace_target_mmap_complete(start); @@ -787,9 +788,11 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong o= ld_size, new_addr =3D -1; } else { new_addr =3D h2g(host_addr); + /* FIXME: Move page flags and target_data for each page. */ prot =3D page_get_flags(old_addr); page_set_flags(old_addr, old_addr + old_size, 0); - page_set_flags(new_addr, new_addr + new_size, prot | PAGE_VALID); + page_set_flags(new_addr, new_addr + new_size, + prot | PAGE_VALID | PAGE_RESET); } tb_invalidate_phys_range(new_addr, new_addr + new_size); mmap_unlock(); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 7f6700c54e..d190fb1122 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4315,8 +4315,8 @@ static inline abi_ulong do_shmat(CPUArchState *cpu_en= v, raddr=3Dh2g((unsigned long)host_raddr); =20 page_set_flags(raddr, raddr + shm_info.shm_segsz, - PAGE_VALID | PAGE_READ | - ((shmflg & SHM_RDONLY)? 0 : PAGE_WRITE)); + PAGE_VALID | PAGE_RESET | PAGE_READ | + (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE)); =20 for (i =3D 0; i < N_SHM_REGIONS; i++) { if (!shm_regions[i].in_use) { --=20 2.25.1 From nobody Tue May 7 13:31:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591330742; cv=none; d=zohomail.com; s=zohoarc; b=aHy6Qmh3ogZhS72P+PN+ofpAI4AZUyUEBmPweN6DIH+Infk8SL2YBDs9ps98a/9J/ARQnMy3Q4UMDwrofXWnXnERlx6JjLcV4KsbX5nYd2/FiltJ3cDKNELWBw3oUTDYg1N3ZKlWU3bfUsCFu0VE/NEBPlEI7dPycYPgZhl8J3o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591330742; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eLZZtVFaB75BQS+spGGXnwizsOQKSuMWVvyzFk16uJw=; b=BLIqZU8gVfyWcw+CQKSBoFoHVVcxpsOJ+bhjDvr34K/Kvt3jbp9sbD8ByTtgdywQGu8sy3WXCj7LK/7Ho9xkcwnVeJuRGsWqnoX+40YbOaNTazfByYBvdG/HgRnm1sitOlcBXnjeFMm2FTD1ImcwhBrm/zIaabXOIa0c74VtraE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591330742887909.4691995686082; Thu, 4 Jun 2020 21:19:02 -0700 (PDT) Received: from localhost ([::1]:41578 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jh3or-0006hn-Fw for importer@patchew.org; Fri, 05 Jun 2020 00:19:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39454) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jh3na-0004Ef-4T for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:42 -0400 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:36156) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jh3nX-0000it-Gb for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:41 -0400 Received: by mail-pj1-x1042.google.com with SMTP id q24so2180561pjd.1 for ; Thu, 04 Jun 2020 21:17:39 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id h15sm5440902pgl.12.2020.06.04.21.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 21:17:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eLZZtVFaB75BQS+spGGXnwizsOQKSuMWVvyzFk16uJw=; b=dkGcpEw/QA8qwpDaDFqgPmDutz39Gfwybi7llJl84hrNtzI8DD261uTAlCrwspeY25 HDasxtEIgKSuUghhmyPWGmEDECPRG9uOGNweAyTvQG7KY/nY/AIlf/Lg8y7KdjTWnFXu +5Tjorxm6GtCjAlWDPyfcdqDcBlOxGX25Q/38/B1uZypAOf4K0qNv7ltf2b0f009/R18 BoXlgvIDdRIboQY4TkqMxQjRGzPjGEeMTSKooxYqv7KRaUX5brtPitOGdnwSHrVXhsqm Y+ob45FpwXUlAE7GTJN+aTOAPOrgvq4lb+1RFzjz7OLxh1otKOH3PuoVmlC+NqlMf4++ V/bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eLZZtVFaB75BQS+spGGXnwizsOQKSuMWVvyzFk16uJw=; b=p/91jvpTahBezvTfLaZH/8a71y5o2L6ROqTqvHVjdEm9fIuUTehanmC012LhDB68vl LjBHzgg01CP8+PtTwKAZGjRt5zuTpT3oo8WqPmNBiPZfH0ZSGpHMzQ3ZWktvO95gbXnq mAYD8j/xypNVVoweyrnZtXm8MjanYiwyHK7In0FGq592l4kWKdGhV5jM2rRwSTExEi8e 5P7n9hVkEckycDWNeY7bkTyloBWTu4t4W4fMNevLet3a/VqboQmXozFbSQ4rVkcpnpsl 03GWsyM4mMTlLT6rnfvr5XLd2EUa3YwbRY+TTUFLiJlJFvBkHqSip32eTHRMiWDelB1H QHxA== X-Gm-Message-State: AOAM532Qe1tcfSiEzPo/np6e0MuPmZXKYL3cteICHzdBplK1SXU9KRKL vdniYDd9X0FvTLEo6eVFjwh1rtPBICc= X-Google-Smtp-Source: ABdhPJzbflzv84kKEfku0V6ceXvoGpKT25K1pl2PVm9aeyzYwzYCpKczwkXcvm+bRljb6hqimjn9TQ== X-Received: by 2002:a17:902:24d:: with SMTP id 71mr5345398plc.12.1591330657785; Thu, 04 Jun 2020 21:17:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 02/17] linux-user: Introduce PAGE_ANON Date: Thu, 4 Jun 2020 21:17:18 -0700 Message-Id: <20200605041733.415188-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200605041733.415188-1-richard.henderson@linaro.org> References: <20200605041733.415188-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1042; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1042.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, qemu-arm@nongnu.org, steplong@quicinc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Record whether the backing page is anonymous, or if it has file backing. This will allow us to get close to the Linux AArch64 ABI for MTE, which allows tag memory only on ram-backed VMAs. The real ABI allows tag memory on files, when those files are on ram-backed filesystems, such as tmpfs. We will not be able to implement that in QEMU linux-user. Thankfully, anonymous memory for malloc arenas is the primary consumer of this feature, so this restricted version should still be of use. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- include/exec/cpu-all.h | 2 ++ linux-user/mmap.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index e5f564fa1f..3cac7750e4 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -277,6 +277,8 @@ extern intptr_t qemu_host_page_mask; #define PAGE_WRITE_INV 0x0020 /* For use with page_set_flags: page is being replaced; target_data cleare= d. */ #define PAGE_RESET 0x0040 +/* For linux-user, indicates that the page is MAP_ANON. */ +#define PAGE_ANON 0x0080 =20 #if defined(CONFIG_BSD) && defined(CONFIG_USER_ONLY) /* FIXME: Code that sets/uses this is broken and needs to go away. */ diff --git a/linux-user/mmap.c b/linux-user/mmap.c index f9832609b0..fdd55986a1 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -599,6 +599,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t target_prot, } } the_end1: + if (flags & MAP_ANONYMOUS) { + page_flags |=3D PAGE_ANON; + } page_flags |=3D PAGE_RESET; page_set_flags(start, start + len, page_flags); the_end: --=20 2.25.1 From nobody Tue May 7 13:31:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591330729; cv=none; d=zohomail.com; s=zohoarc; b=Mq1G6KRdPKXF15GsUWsGtcEvG6JuzXznh2M0j5EJuKGoeH8JbZNaKoSyORlhBeedTfs1JiEfb+9pEjCzmEOpvevGGzbY0sKk0l3pe8yfoAUKzEcLEfOmHRmfuUVEGzgqRm810ySdhrTJkAwGoj0BUHmI1thMAfHi8WThm4wJclo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591330729; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZRhkmFyLy+CEyb6J1D7iziceaKpzHBPMdBM2JQyWlqQ=; b=Hkh1tMnwjkmvhpkkkqa7FzF3uhXwtXj04DY18dutkCQ2LoC38GTPYUFWuFO1hm566kCVXccuBUMgzRvU6vSg7lcLp/ozO8k21awGdDWc0Rp58O2+Wjlqr6irjOiBuhF04SYycvoHJa8un/Ztsl7PS6XFQNK2eiwkjP6qvJvUxiQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591330729938508.50161401594255; Thu, 4 Jun 2020 21:18:49 -0700 (PDT) Received: from localhost ([::1]:40070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jh3oe-000676-BO for importer@patchew.org; Fri, 05 Jun 2020 00:18:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39444) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jh3nZ-0004Ct-G6 for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:41 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:35313) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jh3nY-0000jE-QU for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:41 -0400 Received: by mail-pl1-x630.google.com with SMTP id q16so3121335plr.2 for ; Thu, 04 Jun 2020 21:17:40 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id h15sm5440902pgl.12.2020.06.04.21.17.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 21:17:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZRhkmFyLy+CEyb6J1D7iziceaKpzHBPMdBM2JQyWlqQ=; b=Vik2TrY3sbDhCQs1uBFALhsFBWnCSqhMTMGUe8vIHSiasqnFFjmoYlnOhCNyvtquBC 6juohJ7GcuV4bxqiP07vD8fDhV2lTtf0Kcma4nHAB2TsSnD9FdskV68LR7tZmRTlf7s4 coy0I9HR1cslWBpgA6D2J3CXk9KmceJI2BqdsQgA77T6hLP+LWhaheywD+RmQhyZVu1v HuadP5c0poLmf++YdVB6aogMIa9HI5MKsjqCj3AjqI18afaKUE4KgOt5WXK68M0egpD8 JODNzDJMG9ZDB11/1StKL6Ay/wnEH9RIgQUZAMbaENF1NWZ995nrvZQ2juvAQtSspVc4 uCCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZRhkmFyLy+CEyb6J1D7iziceaKpzHBPMdBM2JQyWlqQ=; b=Fjc9NYrmSIOgfMM6PnMtq5ndImetSFw+/3CREPRhBsY49ATmZJm2P82djQCB7w2aVN 3ansqDIpX5ZOJG6+fx8oXx/Pbc1A6/z58Myp7EDVeTdMwv+OHCioYfhErwelRSaegaaN /b5jLjhSUpxWeXPmUg84RzgD3WpDVpe4oB366DFOh4OmqYvUix3BVRYjgJwxNoaFTIvi 0muSDJ/1MCpi+MgpakWNp5KgRk1KDHzsdl6X/cVHIH/PE46bT32R9Y+qHlR96WSovPmt 0rQSNnEP3kQaInFSg8wM+Yk75ENIpneKZzRTvyNyZ8vKEqPT4xN6AX6kxF+v0CsJANdk 4giA== X-Gm-Message-State: AOAM531VlNeNmCRR2xIXhhwsQNXQcl7EzJJsGa7VMhJQex/yQmZVzjhi P5rFG8GeNTOZzWGGEaBwWdTQQgKN9Gc= X-Google-Smtp-Source: ABdhPJyli7hHRAflUuzYSn+oNzwISJOrnmSwDDnh6TBBuYBLrsBTHl4raY1YQ00q0Bt/lKIIll4Jwg== X-Received: by 2002:a17:902:9889:: with SMTP id s9mr7367283plp.299.1591330659134; Thu, 04 Jun 2020 21:17:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 03/17] linux-user: Check for overflow in access_ok Date: Thu, 4 Jun 2020 21:17:19 -0700 Message-Id: <20200605041733.415188-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200605041733.415188-1-richard.henderson@linaro.org> References: <20200605041733.415188-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, qemu-arm@nongnu.org, steplong@quicinc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Verify that addr + size - 1 does not wrap around. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- linux-user/qemu.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index d36b18b678..2bf35e66ac 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -467,12 +467,19 @@ extern unsigned long guest_stack_size; #define VERIFY_READ 0 #define VERIFY_WRITE 1 /* implies read access */ =20 -static inline int access_ok(int type, abi_ulong addr, abi_ulong size) +static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) { - return guest_addr_valid(addr) && - (size =3D=3D 0 || guest_addr_valid(addr + size - 1)) && - page_check_range((target_ulong)addr, size, - (type =3D=3D VERIFY_READ) ? PAGE_READ : (PAGE_= READ | PAGE_WRITE)) =3D=3D 0; + if (!guest_addr_valid(addr)) { + return false; + } + if (size !=3D 0 && + (addr + size - 1 < addr || + !guest_addr_valid(addr + size - 1))) { + return false; + } + return page_check_range((target_ulong)addr, size, + (type =3D=3D VERIFY_READ) ? PAGE_READ : + (PAGE_READ | PAGE_WRITE)) =3D=3D 0; } =20 /* NOTE __get_user and __put_user use host pointers and don't check access. --=20 2.25.1 From nobody Tue May 7 13:31:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591330833; cv=none; d=zohomail.com; s=zohoarc; b=bIektmnebVRplxax6SWh2Tc6PAytXKk4gevGfEALbCsLb+yXrODNL5gqtvo+im2ok/OQSutlsMAItG8T6SI//B0vMxIttWII/ywBnE5SuJYzZTWrmRdlQ9QM2fgctvZqLKSAkaM4i/yDn2GyuMk7B3V2gZ9BHGieuUjztYn5uMM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591330833; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nqqofQziFBqWdXP+8khcoigsyFvMbdt2vH117/pVwFo=; b=PDu0m5zgxdTpv7l1OoKokHevu+cfkYZ2YZWDfMGiS8gzd2rhGBJnwyWMqgo4GI8pTinum427QdjZ59omTfhquIKySozSHpDml1xMql6CGz1NBEXAcKPgbbtVq6fjk0iPjsH+//2V2m6oVzueiHlbgZKyVKpYxIEAQX02zBEEGvE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591330833386696.0399254560677; Thu, 4 Jun 2020 21:20:33 -0700 (PDT) Received: from localhost ([::1]:50270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jh3qK-0001v5-1c for importer@patchew.org; Fri, 05 Jun 2020 00:20:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jh3na-0004G4-JM for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:42 -0400 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]:52419) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jh3nZ-0000jW-SK for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:42 -0400 Received: by mail-pj1-x1041.google.com with SMTP id k2so2054723pjs.2 for ; Thu, 04 Jun 2020 21:17:41 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id h15sm5440902pgl.12.2020.06.04.21.17.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 21:17:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nqqofQziFBqWdXP+8khcoigsyFvMbdt2vH117/pVwFo=; b=xyKzTnUoermMpUwPDDOvda0xWv7DakzouPKnECbhodlQTTmqQHY3y5wDHVpNUkudKc 5nZMV4J5d3QeKHmtH/WKEU8h8mGbFhgS+qjoJx7OmYNf1/ZSHSavCutMk74RS2TDX1IU IlXPdq1uDZlj9vKIDz/fW+nFGTrbkqf/cBZv0rkNYXliiE7aT/Nk2gSIBzi2UA+Lxu6q mYHxAn5sKl/AuOASnN5mNnjdi5BPyY9USNVxBH51SPKnDiSvQDGCP9Z5URJQsp46kbHh g+Er9rkYF9X1iR0svgXb0JeAR9ONRR1ZVL3padv8JVnV4D8e2NPSn1azB4JzoCgR7ffa hcYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nqqofQziFBqWdXP+8khcoigsyFvMbdt2vH117/pVwFo=; b=mGQomlIZX227NHPiPoAoV/x8nrnCaIEUepyTeUVnwE4qkofurAu0mq0pz7zAKwF+CV qvX9jpsILILaWmFpbD+o2vOY/6JDMtlfOBYEzPpMloC859VGpYDFiY7dgMrAgJqUjMLH /km6mngLuQuyDKofnIM1wOKG9xTki3iGq1xIBT7yH8/f/zirNY7qaGC/HJfI9We2M7xO DcfGt8lGUzT7914kyoeo2i78bMq4FWLpK0WYV9fotoCfLuq94rA62UYQ/09p4lha7oNr NaKMvfi8HUyLq9kRGBTAIYyZJ0wy/lmi56FO8oQnrhv1dGYiuqMjWx61F6aVBZ0IfJcd px0A== X-Gm-Message-State: AOAM530JOdSusFpEvyr2/WhCzT8nDYKwF3ZGcESBCGtWINLGeTHaTEQi 82B8ZLY32KRL4Vq/hPVIKUm/MEkjRFk= X-Google-Smtp-Source: ABdhPJwFDYVvMiy2eMcza5GBkDYBUYtsdGeV7Tpyo2G42Ak0L7S6k/H0dVViCIBtrZtaCtF69ZB2fQ== X-Received: by 2002:a17:90a:17ed:: with SMTP id q100mr740057pja.80.1591330660238; Thu, 04 Jun 2020 21:17:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 04/17] linux-user: Tidy VERIFY_READ/VERIFY_WRITE Date: Thu, 4 Jun 2020 21:17:20 -0700 Message-Id: <20200605041733.415188-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200605041733.415188-1-richard.henderson@linaro.org> References: <20200605041733.415188-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1041; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1041.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, qemu-arm@nongnu.org, steplong@quicinc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" These constants are only ever used with access_ok, and friends. Rather than translating them to PAGE_* bits, let them equal the PAGE_* bits to begin. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- linux-user/qemu.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 2bf35e66ac..a8dde8c609 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -464,8 +464,8 @@ extern unsigned long guest_stack_size; =20 /* user access */ =20 -#define VERIFY_READ 0 -#define VERIFY_WRITE 1 /* implies read access */ +#define VERIFY_READ PAGE_READ +#define VERIFY_WRITE (PAGE_READ | PAGE_WRITE) =20 static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) { @@ -477,9 +477,7 @@ static inline bool access_ok(int type, abi_ulong addr, = abi_ulong size) !guest_addr_valid(addr + size - 1))) { return false; } - return page_check_range((target_ulong)addr, size, - (type =3D=3D VERIFY_READ) ? PAGE_READ : - (PAGE_READ | PAGE_WRITE)) =3D=3D 0; + return page_check_range((target_ulong)addr, size, type) =3D=3D 0; } =20 /* NOTE __get_user and __put_user use host pointers and don't check access. --=20 2.25.1 From nobody Tue May 7 13:31:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591330826; cv=none; d=zohomail.com; s=zohoarc; b=cgI4NQeDltqUD43x9RWPkgiZ9ymUb7gHBCe1ylsFsyhtAvKN/B4IN4ShtY/uxOdR0TGqctmkOvQZNlKcGdFsSYurwINjjS8p/bZWmdApyKauRqOzii6hWpLskC5jErtxdDalrKr9DiVpPpBSwnaBYk4wMLDiJuChjkP18Ssxr/g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591330826; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OQXnnFtOsPYN4aWlItYREcPDVPLVM/BSGRYhyFhu/u4=; b=cDovyrJq8mgAQ2OiF7lIMx3sz4lcD6uV3gEOPaZ6GxoOeAQJoJnSjl2H+bO5/Q5SPRkghTDFXEdwCzQQwaDYtn7YRPujofhvFkY+fClgtbvQapBnotpTTMu2xaf6y3OC129PcBKpFFKXwVLDR9ThcoY0qFjnT+787Au6el1NTkc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591330826428892.4897069806065; Thu, 4 Jun 2020 21:20:26 -0700 (PDT) Received: from localhost ([::1]:49548 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jh3qD-0001cd-6b for importer@patchew.org; Fri, 05 Jun 2020 00:20:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jh3nb-0004Jl-RC for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:43 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:52421) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jh3nb-0000jq-3V for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:43 -0400 Received: by mail-pj1-x1043.google.com with SMTP id k2so2054748pjs.2 for ; Thu, 04 Jun 2020 21:17:42 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id h15sm5440902pgl.12.2020.06.04.21.17.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 21:17:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OQXnnFtOsPYN4aWlItYREcPDVPLVM/BSGRYhyFhu/u4=; b=O9JjXFcZnzH+YSBGRYdrGc/qCUzYaB6ZiEjMWnVqQCxxz/otE7MxzOQ/JMz9Y/Vw2D vnZd1Y2L/BM+yysvq91YzkFaUeTm3RZEDPqDKFilOIRiQ94V9s7GUFwsglPG7EeKEJm9 grNbCjVQzE5Gi5+40pNdAxL8GG1Nre4Zfvsj3vPNWixXe3Y/26ynnUzoo3qP5XoXVY93 eQy+1ClaHRVdRN7oTRgBHzjarax1ikbC4EfUrtEO116zJ0B51SeZx+Oit4FBgc7hcfYW j6sk6brBir2LeNo0J3XYoKcb/MpT0ObBcBKdlg2ZCsZeIXUVD29MxDZWV7i60sojO8XP 6Crw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OQXnnFtOsPYN4aWlItYREcPDVPLVM/BSGRYhyFhu/u4=; b=J9mM6sWiH4iEZ9OHYBSCf+nPOv1XgLUi5Mba7wfvRqyIEU1bD/5hky+S12skFlT3vi ytimQCArHjrgh8ONpDsynO9xr17krpOXN91U1Op3dOgq7ReNdMKIy72S4rFfQ3WnXDiJ lLCvUuskdTP2LRu4Pwk13xZ4bQ5hp6DH/sLA20xUjIFqwUDUKGRwJar0WAivi6X8rBDw eavu522OBCzFrsIRii5zqEatGUdHQT0GBL2KAKXjxzZW+OliGU134TEDZXg55smncOOJ PAgKzYsB/3+7OZeqgMFnCc/9cXRPbnfCn7XhnApWNdVexjWuiOo8EdGnrMWyhqpW18Nk x3Iw== X-Gm-Message-State: AOAM533Z90qvyILRhlx1ddLugZ/5ZOcti6hLMfesnpMwrQeXD32WyBCX 8wkO+A6X7zACSX7CKs66UMlN9+1vpw8= X-Google-Smtp-Source: ABdhPJwSXiiKJeWvqegpBNqwQbkNj0W8Q4QxCR9gp4LCzP0H/5dYuNCL5mh9zt+lGnEdhr5zBtKTCg== X-Received: by 2002:a17:90a:9604:: with SMTP id v4mr768386pjo.198.1591330661509; Thu, 04 Jun 2020 21:17:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 05/17] bsd-user: Tidy VERIFY_READ/VERIFY_WRITE Date: Thu, 4 Jun 2020 21:17:21 -0700 Message-Id: <20200605041733.415188-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200605041733.415188-1-richard.henderson@linaro.org> References: <20200605041733.415188-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1043; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1043.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, qemu-arm@nongnu.org, steplong@quicinc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" These constants are only ever used with access_ok, and friends. Rather than translating them to PAGE_* bits, let them equal the PAGE_* bits to begin. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- bsd-user/qemu.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index f8bb1e5459..4076adabd0 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -218,13 +218,12 @@ extern unsigned long x86_stack_size; =20 /* user access */ =20 -#define VERIFY_READ 0 -#define VERIFY_WRITE 1 /* implies read access */ +#define VERIFY_READ PAGE_READ +#define VERIFY_WRITE (PAGE_READ | PAGE_WRITE) =20 -static inline int access_ok(int type, abi_ulong addr, abi_ulong size) +static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) { - return page_check_range((target_ulong)addr, size, - (type =3D=3D VERIFY_READ) ? PAGE_READ : (PAGE_= READ | PAGE_WRITE)) =3D=3D 0; + return page_check_range((target_ulong)addr, size, type) =3D=3D 0; } =20 /* NOTE __get_user and __put_user use host pointers and don't check access= . */ --=20 2.25.1 From nobody Tue May 7 13:31:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591330922; cv=none; d=zohomail.com; s=zohoarc; b=ftMi0yMXCxcHbx1avhVILzR2WYq0LWpoznAUxLK6OHa/oYXp6OWB9dWvMVAXq4huFLGf7t/K18MaCkGMlBSjrZE/FGYoznE8JLA+e8ZuVwjIoLYHrFnItzK+FfI+Wpd2WEL8idYKdsUMAz2FDT75+NMwYi42r0rjFuiCsGEX/Tc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591330922; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mHdkZW2BtXgCCzUvavDtufJgojf9AzZZHlwJyJIkodU=; b=kQujpiHxLVa33xi+WwyqxqAOJjTA8uX8ASv2WfsEB8O6xKkMhwMxWpDqzqTwqOR9ohs80q+2o6Ao2uODvM5wJa4ZG4c6P3o3HfFsYxvssPTf9kRrQKmiZLwXFvoUEUoFb7kje17HrlJWfqTEiaSn68CumsbF+Bl+l9uvhrxdcSo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591330922657867.7127650532502; Thu, 4 Jun 2020 21:22:02 -0700 (PDT) Received: from localhost ([::1]:58150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jh3rl-0005F5-ET for importer@patchew.org; Fri, 05 Jun 2020 00:22:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39486) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jh3nd-0004Nt-4h for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:45 -0400 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:38083) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jh3nc-0000k4-BQ for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:44 -0400 Received: by mail-pj1-x1042.google.com with SMTP id d6so2180032pjs.3 for ; Thu, 04 Jun 2020 21:17:43 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id h15sm5440902pgl.12.2020.06.04.21.17.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 21:17:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mHdkZW2BtXgCCzUvavDtufJgojf9AzZZHlwJyJIkodU=; b=A0tjNfKG6o69Lfe9DGoQRD5xlUXCVE3IYgfK4e7eSVqCxRoJeP+FDG4Ufc9QSEhVVN BF/fnDWIPQEWhfJL9VG1bGcmgvAPP0TQw77ZOtbFm+wtuv7aXUZBO6lj57lqJYT5QWCd AXEk+pKZC7KjL+U2FUX2+94bO8y0VSwCJOBbDmBseywpQpO3XiZ8oZdvWXiWB6eyaGwB QcFjTHP1k10npcJwNwG/iwZC+LKii0S0hw5JzdbJA868koVF6GHvpIjMnngR02Hvqo0m wXZnY3XLVzepBIpLclJvUWZFB1FtB4z8cJa0lrx9UxKHPCcgbBBPjEtK9Wq1jV4vYJkQ Weug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mHdkZW2BtXgCCzUvavDtufJgojf9AzZZHlwJyJIkodU=; b=WEEcpnByuKF7RGAGU3ypbZc1KAyHCTFBulrvhqR1bb/LEGJAbV3eS/XAULd9Bkgczm C+d1hx6MIfBesu+92qFj3QC5eUb6oTjRv4Qg0vNeOeSPsETACvMW3KLvmW06ttRlh8k4 UIIKkIxvRdMRO3WYUK80s6B5BqMM6jcrqKMszsbC1exaNJKjkDlldQKjR+Rq5MHoc21P /xKTgUn+suQSNjpnwPKsUQaFWjFge+76iEOBd7g9vEhphZ4tLMsfvC3vSH5vtCR3muuk v/y7b6jYCQqesLVNKkeZDt0GPupjEOo5VzPL8sXoXzIROnF7CGVTiuu5w05CwV/wor6B 3kbg== X-Gm-Message-State: AOAM5338i/08oNkW6F4HPjojcSPEJYOUJ5VsUxzbvUXafay5MhHcvb/L n1leRAmw8F3rmmEU9J3hLoYORem888A= X-Google-Smtp-Source: ABdhPJwctokSJwMErfDPEYCtZO4AWVtcyE3yWYzmPyIPu/maWAYpnSJICjtLbuzfwB1NE1SFh5yFMg== X-Received: by 2002:a17:90b:605:: with SMTP id gb5mr699334pjb.167.1591330662669; Thu, 04 Jun 2020 21:17:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 06/17] linux-user: Do not use guest_addr_valid for h2g_valid Date: Thu, 4 Jun 2020 21:17:22 -0700 Message-Id: <20200605041733.415188-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200605041733.415188-1-richard.henderson@linaro.org> References: <20200605041733.415188-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1042; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1042.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, qemu-arm@nongnu.org, steplong@quicinc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This is the only use of guest_addr_valid that does not begin with a guest address, but a host address being transformed to a guest address. We will shortly adjust guest_addr_valid to handle guest memory tags, and the host address should not be subjected to that. Move h2g_valid adjacent to the other h2g macros. Signed-off-by: Richard Henderson --- include/exec/cpu_ldst.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h index c14a48f65e..3930362e20 100644 --- a/include/exec/cpu_ldst.h +++ b/include/exec/cpu_ldst.h @@ -77,15 +77,16 @@ typedef uint64_t abi_ptr; #else #define guest_addr_valid(x) ((x) <=3D GUEST_ADDR_MAX) #endif -#define h2g_valid(x) guest_addr_valid((unsigned long)(x) - guest_base) =20 static inline int guest_range_valid(unsigned long start, unsigned long len) { return len - 1 <=3D GUEST_ADDR_MAX && start <=3D GUEST_ADDR_MAX - len = + 1; } =20 +#define h2g_valid(x) ((uintptr_t)(x) - guest_base <=3D GUEST_ADDR_MAX) + #define h2g_nocheck(x) ({ \ - unsigned long __ret =3D (unsigned long)(x) - guest_base; \ + uintptr_t __ret =3D (uintptr_t)(x) - guest_base; \ (abi_ptr)__ret; \ }) =20 --=20 2.25.1 From nobody Tue May 7 13:31:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591330834; cv=none; d=zohomail.com; s=zohoarc; b=V9w+gMMgZXcv5e95ZFvQSl1x8bZGoLW2MZrSH6/hZqd+aKLYWFW5UiUq33HCovZ2tXD1zltKMOZKZMaGxouCV7e+nwVOUXXQskRya+fH3cxgxW3QlsbdAaK+xfNOusWVkOjea3Y9THd7cHWEZe/OjYMzBewh8/2FgLTKAdYZ6AE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591330834; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IX3UPP0As7IJLtjhajwCoyh2nTlTRQqiCGAXcYWkMx4=; b=LljImsh/APqG9i8/tHJWhV3mPi3YlZ9KktMIfpHuET4JJoKq066d2egfrE+ZLAiErn8idCrV+NCFUjqY/0duWwU0VQZ/uc43x/w+JszDcBXvPXTQtodP72YlBgF5hM8XtfzGy3HkV9E8BBnW0Jt1ozfTz1jZRXAd8Uq47q98Pr8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591330834134440.72641657630027; Thu, 4 Jun 2020 21:20:34 -0700 (PDT) Received: from localhost ([::1]:50330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jh3qK-0001wT-Qh for importer@patchew.org; Fri, 05 Jun 2020 00:20:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39500) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jh3ne-0004Qf-06 for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:46 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:35584) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jh3nd-0000kQ-9w for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:45 -0400 Received: by mail-pj1-x1043.google.com with SMTP id 5so2179509pjd.0 for ; Thu, 04 Jun 2020 21:17:44 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id h15sm5440902pgl.12.2020.06.04.21.17.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 21:17:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IX3UPP0As7IJLtjhajwCoyh2nTlTRQqiCGAXcYWkMx4=; b=c5IIcB5FKwiU5Shz5dBmNSFf2/+yMQYk3+n1aXADbGuu7tvM0D77n1PiYwK/aL77Aq tGwy5FJ2AH5OBcRGodiau7ZzLu70Uama4OjM/xxjE0BPRDEaycvEVmariATtEPoOX9ol UQdn4dzFFmQ7lylVEznpWAUtAuqmKUJqeoXZqYxke3m+ZV3IiV7uVpb32qRgBXJEP99T SFmJBcsTgPqOYi2cXcuX0hiNVkTBoe3MG2ym/RSi9+vxeCRmHEoVTKwDG1FUEN65h5Le i2RHeiDs7atAu/zCFZh4rPK/YZfhQfeFLrQMZODy7xeEuSYnlGxyePMvUjVOsxHuqqtS 3P6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IX3UPP0As7IJLtjhajwCoyh2nTlTRQqiCGAXcYWkMx4=; b=ZfXoRp86VutsEgn3yPBUIXKB7uzvFfs/HNjS9DnQwiZQ/7Z4+n8kYELOnn6poe+s4D iBf9jxph8h5P362DrNa84/wo9tWnso7M58MS/ti1s2Jm8bHr4WnfonvYbTm5haL2AKGm c/GaOl800LWdYVup2XfljuKJTfMnXZjYGynN9I4hgCdIxrRskgmglSoNNROTolkBsRfL yPHVmiXgemdmGKbrYDexXHE3z3IkByD6JpOCTVn3DYMzM9C+T+gX0dejVUcCVM7rj68G Iw9oO8rnruqz6wjAqcJlYGl0yO0akFpqhMNCj7QqENzi7kUa90fV86F5XSJ8d7j+Wzmo xY4w== X-Gm-Message-State: AOAM530Qjs2S1otysk0ODbmWyqrLkFjozi/3v/jjG88SGUcVdNyqZXgG wHtaxi34fGcwW10kBgYfZN3wjoITneE= X-Google-Smtp-Source: ABdhPJwIxlO7xYTHArB3jOysYqxblDCQBahjSZfQDMvEQONmORNB9pMs8oHlwndW3bKDgubS4PvHgg== X-Received: by 2002:a17:90b:283:: with SMTP id az3mr777657pjb.232.1591330663718; Thu, 04 Jun 2020 21:17:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 07/17] linux-user: Fix guest_addr_valid vs reserved_va Date: Thu, 4 Jun 2020 21:17:23 -0700 Message-Id: <20200605041733.415188-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200605041733.415188-1-richard.henderson@linaro.org> References: <20200605041733.415188-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1043; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1043.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, qemu-arm@nongnu.org, steplong@quicinc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We must always use GUEST_ADDR_MAX, because even 32-bit hosts can use -R to restrict the memory address of the guest. Signed-off-by: Richard Henderson --- include/exec/cpu_ldst.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h index 3930362e20..066cf33f70 100644 --- a/include/exec/cpu_ldst.h +++ b/include/exec/cpu_ldst.h @@ -72,11 +72,10 @@ typedef uint64_t abi_ptr; /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ #define g2h(x) ((void *)((unsigned long)(abi_ptr)(x) + guest_base)) =20 -#if HOST_LONG_BITS <=3D TARGET_VIRT_ADDR_SPACE_BITS -#define guest_addr_valid(x) (1) -#else -#define guest_addr_valid(x) ((x) <=3D GUEST_ADDR_MAX) -#endif +static inline bool guest_addr_valid(abi_ptr x) +{ + return x <=3D GUEST_ADDR_MAX; +} =20 static inline int guest_range_valid(unsigned long start, unsigned long len) { --=20 2.25.1 From nobody Tue May 7 13:31:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591330961; cv=none; d=zohomail.com; s=zohoarc; b=mSqA+sGUfxFs7ZmVA9iVt3gxdwqau7c2wsoDVJ3P5TFZuhc6L/WA+7Wkrqmxj7blCHigPclWKQSd7t0GNk7vhXsyISe/HnrdPcJmnQvig+gU5rmvW2UQI6ILFJRxlJD/VJaMygB16faSSRh1B0Vsy1DfusYI15np+Rz5BSk2Go4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591330961; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nCxIirgN5OzmYmJJvTz1Ncldrcyg3LSoeyCRUE7/tl0=; b=VyjvlY3qZncOplyBUtFfrJ/YFvFDkPOZxuflHiBFQgPjnUxTWIS/BSsyiM/M6GuP9q1aoknsFoTQTtUL7gQ0jLnb7aMhfgnXDLdf043GHy3I9LL3oXk2+agSUd/0caBQ7oaS1+cMme7D74faqsDcTJ90ujesF0conI5c+A5BujQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591330961611850.5424068467939; Thu, 4 Jun 2020 21:22:41 -0700 (PDT) Received: from localhost ([::1]:60858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jh3sO-0006M0-BT for importer@patchew.org; Fri, 05 Jun 2020 00:22:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39514) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jh3nf-0004Uk-Cb for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:47 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:40216) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jh3ne-0000kh-Il for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:47 -0400 Received: by mail-pj1-x1043.google.com with SMTP id s88so2179647pjb.5 for ; Thu, 04 Jun 2020 21:17:46 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id h15sm5440902pgl.12.2020.06.04.21.17.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 21:17:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nCxIirgN5OzmYmJJvTz1Ncldrcyg3LSoeyCRUE7/tl0=; b=YxMROiUmSMWoMRilm0Ow7tHnIWiDyjBi33Ml7dfIqbCZtEUDsT+NFO9ubOAnOb0WE3 uBB5vDn6D6ta07XlPURgTyJW7kDEklNuHOr6eYuE7jg7kAbZYBRxGtvuJxRKEC6wRsa1 2Ue0vfJsJXvw1ctA1QOLZDpPztNkwBao6fUlaRzBNJSjj/ruCMXvPZLH6itcx6pu5qko ner6WCZamoZZrIUlVR+FkGMfZXdK3wKzYc2P+/xh888lQsRVawCZ/RrnHsmRHZI/ZtN8 t8WqwqM9ne333TErHpYu+n3naILGXfYnGugrK5UAjjzSEwzcgT0rXCGhSP5UBGbn141p 0OKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nCxIirgN5OzmYmJJvTz1Ncldrcyg3LSoeyCRUE7/tl0=; b=lJneh+VPJtTeT2m8QMgLW2RzzqeUpRP5AWGtVqSAm0UOaYfNjBXI5nltuFPkCb5O1q +OXB4u/ZsVV3U3ep2qzUONHR9z8pxcN3FEkxQ3Y/Es8hbcsvRVB4qx1H9/67cmyCVupU VmE17bsnb8QaotpHxv03Kv4+4GV7EvtMHPNEWeEbMvK7x9JS4bsxXhwqTCMu5JU2SbiN 4tfXq0dNDhyMkcztBO14Zk6eYAnwWtPWmjXYKaWHq8KQJjGvgewx6eqdaqlKfXZofLYj 17l+oIZDCxXlOlVzqhXQHCfjI5z8Q55m+liP9GftV+39Bro/Hcy21udHprtuRNsI4x75 6Piw== X-Gm-Message-State: AOAM530U/8s7Z0VIKeJ2s2ZlQujMQREAa4mW0EOwntLhMCW0Rb/MnTtd u4fhjmf3vb3u9f1e1fFugh5JaG4Ed+o= X-Google-Smtp-Source: ABdhPJzjUUWZPyLui9Jga+9L7iKRXYDte6mM3iDJnjJK6TqvJIDN2pGqIPOGCkOVOsl1T+0Vq266hg== X-Received: by 2002:a17:90a:6047:: with SMTP id h7mr738751pjm.145.1591330664883; Thu, 04 Jun 2020 21:17:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 08/17] exec: Add support for TARGET_TAGGED_ADDRESSES Date: Thu, 4 Jun 2020 21:17:24 -0700 Message-Id: <20200605041733.415188-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200605041733.415188-1-richard.henderson@linaro.org> References: <20200605041733.415188-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1043; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1043.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, qemu-arm@nongnu.org, steplong@quicinc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The AArch64 Linux ABI has always enabled TBI, but has historically required that pointer tags be removed before a syscall. This has changed in the lead-up to ARMv8.5-MTE, in a way that affects the ABI generically and not specifically to MTE. This patch allows the target to indicate that (1) there are tags and (2) whether or not they should be taken into account at the syscall level. Adjust g2h, guest_addr_valid, and guest_range_valid to ignore pointer tags, similar to how TIF_TAGGED_ADDR alters __range_ok in the arm64 kernel source. The prctl syscall is not not yet updated, so this change by itself has no visible effect. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- include/exec/cpu_ldst.h | 22 ++++++++++++++++++---- target/arm/cpu-param.h | 3 +++ bsd-user/main.c | 5 +++++ linux-user/main.c | 5 +++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h index 066cf33f70..d84847dc70 100644 --- a/include/exec/cpu_ldst.h +++ b/include/exec/cpu_ldst.h @@ -69,17 +69,31 @@ typedef uint64_t abi_ptr; #define TARGET_ABI_FMT_ptr "%"PRIx64 #endif =20 +#ifdef TARGET_TAGGED_ADDRESSES +extern abi_ptr untagged_addr_mask; +static inline abi_ptr untagged_addr(abi_ptr x) +{ + return x & untagged_addr_mask; +} +#else +static inline abi_ptr untagged_addr(abi_ptr x) { return x; } +#endif + /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ -#define g2h(x) ((void *)((unsigned long)(abi_ptr)(x) + guest_base)) +static inline void *g2h(abi_ptr x) +{ + return (void *)(uintptr_t)(untagged_addr(x) + guest_base); +} =20 static inline bool guest_addr_valid(abi_ptr x) { - return x <=3D GUEST_ADDR_MAX; + return untagged_addr(x) <=3D GUEST_ADDR_MAX; } =20 -static inline int guest_range_valid(unsigned long start, unsigned long len) +static inline bool guest_range_valid(abi_ptr start, abi_ulong len) { - return len - 1 <=3D GUEST_ADDR_MAX && start <=3D GUEST_ADDR_MAX - len = + 1; + return len - 1 <=3D GUEST_ADDR_MAX && + untagged_addr(start) <=3D GUEST_ADDR_MAX - len + 1; } =20 #define h2g_valid(x) ((uintptr_t)(x) - guest_base <=3D GUEST_ADDR_MAX) diff --git a/target/arm/cpu-param.h b/target/arm/cpu-param.h index 6321385b46..f922aa0650 100644 --- a/target/arm/cpu-param.h +++ b/target/arm/cpu-param.h @@ -20,6 +20,9 @@ =20 #ifdef CONFIG_USER_ONLY #define TARGET_PAGE_BITS 12 +# ifdef TARGET_AARCH64 +# define TARGET_TAGGED_ADDRESSES +# endif #else /* * ARMv7 and later CPUs have 4K pages minimum, but ARMv5 and v6 diff --git a/bsd-user/main.c b/bsd-user/main.c index 0bfe46cff9..87c99fc6c2 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -45,6 +45,11 @@ unsigned long guest_base; bool have_guest_base; unsigned long reserved_va; =20 +#ifdef TARGET_TAGGED_ADDRESSES +/* Default to no tagged addresses, i.e. all pointer bits valid. */ +abi_ptr untagged_addr_mask =3D -1; +#endif + static const char *interp_prefix =3D CONFIG_QEMU_INTERP_PREFIX; const char *qemu_uname_release; extern char **environ; diff --git a/linux-user/main.c b/linux-user/main.c index 3597e99bb1..8fcca3f5f1 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -103,6 +103,11 @@ static int last_log_mask; =20 unsigned long reserved_va; =20 +#ifdef TARGET_TAGGED_ADDRESSES +/* Default to no tagged addresses, i.e. all pointer bits valid. */ +abi_ptr untagged_addr_mask =3D -1; +#endif + static void usage(int exitcode); =20 static const char *interp_prefix =3D CONFIG_QEMU_INTERP_PREFIX; --=20 2.25.1 From nobody Tue May 7 13:31:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591330945; cv=none; d=zohomail.com; s=zohoarc; b=ZSuCWiGR+lD8sO6vTTNMbKB+HuTzC5wwWAdZ6Ek5470Vuet3nyW2/ZZedZ0GLsWqSg48YRzygfNBEEMV1UvNxhT7OhMQWx3B4X8Ei+T3bGR9P/40T3vz7TAqAFiNlAmBouQJ3skSHm+Lrz+vsh1taMF8u+KcKGblA1pdBXo0w1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591330945; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=icu8Xm8+iq0LFQnztaWvz0M6KFnN5WeXG+dX4xSgCB0=; b=Wmlp54q9ZqvGiEWen0MBCXCmYmm8t5oHnuECHWVtoUuP5jvlbz1qNv8oICtX+QuQk/rwPCaQbAeSiyKjvoGLSG2H9JK3ABMWQxdCquqHDP09TWVf+IIgGitNY3WbZqhhUQXpW4YazKszjkFAcSTdDyfm9sT+naMGRIuSJaI3w/c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591330945079510.5575204294157; Thu, 4 Jun 2020 21:22:25 -0700 (PDT) Received: from localhost ([::1]:59198 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jh3s7-0005ey-OH for importer@patchew.org; Fri, 05 Jun 2020 00:22:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39526) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jh3ng-0004YU-Nu for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:48 -0400 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:50428) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jh3nf-0000kw-PO for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:48 -0400 Received: by mail-pj1-x1042.google.com with SMTP id jz3so2057014pjb.0 for ; Thu, 04 Jun 2020 21:17:47 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id h15sm5440902pgl.12.2020.06.04.21.17.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 21:17:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=icu8Xm8+iq0LFQnztaWvz0M6KFnN5WeXG+dX4xSgCB0=; b=ENhlwBTPAICF2kxkscsFd9h5uKG0+SgIUId49kIUuFpcoHB9bONUg3CxMO1dsSB13F d2beu93TTZp5rDNJbnIFfRNo5WpId2QtnU1gtjkcSGreHEBDx03NNxhfpfpD7Aw9WUOM I5H3llmqRMkcLPI9DDBXaokQbBzQOXaceOEBGr0sp8jln2RB/AK16wSYZhX8giaYAO9T ujVEK7YDtkI+mUn1+RYmfsPCaaqCFY8wnEDEVPSi9/NPdBpxec6F//uKhssfBGPTyrRJ 4B1lWzXixcWNuQmT2YcvKcERPaOYi/XDuBMTFXtTyveW8YbOnFFfHMh+0Aqneb/XZOPm bphQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=icu8Xm8+iq0LFQnztaWvz0M6KFnN5WeXG+dX4xSgCB0=; b=S/jhcwY9J5Bp9zFpcLPdTZJrPCMYT0GsuCgxpaEA0hYjKu9ABTb4Bm58lzkEOJDEwx 5ujIUCFjZ3bUcyOwFKfN4wHhIcnTdbHCLMByQVmjYsE3UV/MYMi6cHdn5ttBrjX5EMdM 00jaMJekeKmqQkmQNPLVjS8oQy1l8rHobCekApEPqrBjQgz8v29t1ks7/Z+3fjnm/ufG wQGztxXHEXV+12hILLtFbuh7iI1fE5COlaVL8h99veLyN8ETBWRrcwIbWcQTf2/0QffT 6lAhYFoFjvTDW490w/JDW2SdY3Fp7BR0YS5e+yDg48Kl8EeML52zb/mUfDZa3bm6TN9k 8P9w== X-Gm-Message-State: AOAM533UsJhNcIX7ClPkakUHw/5/LOk0uDv1xD4IBwPR1WGEqNI9v8cW Nb37XBM8zwfX61crxL7VYluHiWLTIUw= X-Google-Smtp-Source: ABdhPJx8ml2qgvN53/sQuOFKl3ajEDeK3rLf3hymF8RR20lvSJn253hHmsa1ufVJis1OY863HtLqsQ== X-Received: by 2002:a17:902:7d8a:: with SMTP id a10mr7643821plm.116.1591330666007; Thu, 04 Jun 2020 21:17:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 09/17] linux-user/aarch64: Implement PR_TAGGED_ADDR_ENABLE Date: Thu, 4 Jun 2020 21:17:25 -0700 Message-Id: <20200605041733.415188-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200605041733.415188-1-richard.henderson@linaro.org> References: <20200605041733.415188-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1042; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1042.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, qemu-arm@nongnu.org, steplong@quicinc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This is the prctl bit that controls whether syscalls accept tagged addresses. See Documentation/arm64/tagged-address-abi.rst in the linux kernel. Signed-off-by: Richard Henderson --- linux-user/aarch64/target_syscall.h | 4 ++++ linux-user/syscall.c | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/linux-user/aarch64/target_syscall.h b/linux-user/aarch64/targe= t_syscall.h index 995e475c73..5fb0bf4a5d 100644 --- a/linux-user/aarch64/target_syscall.h +++ b/linux-user/aarch64/target_syscall.h @@ -29,4 +29,8 @@ struct target_pt_regs { # define TARGET_PR_PAC_APDBKEY (1 << 3) # define TARGET_PR_PAC_APGAKEY (1 << 4) =20 +#define TARGET_PR_SET_TAGGED_ADDR_CTRL 55 +#define TARGET_PR_GET_TAGGED_ADDR_CTRL 56 +# define TARGET_PR_TAGGED_ADDR_ENABLE (1UL << 0) + #endif /* AARCH64_TARGET_SYSCALL_H */ diff --git a/linux-user/syscall.c b/linux-user/syscall.c index d190fb1122..e4da53c5b3 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -10460,6 +10460,29 @@ static abi_long do_syscall1(void *cpu_env, int num= , abi_long arg1, } } return -TARGET_EINVAL; + case TARGET_PR_SET_TAGGED_ADDR_CTRL: + { + abi_ulong valid_mask =3D TARGET_PR_TAGGED_ADDR_ENABLE; + + if ((arg2 & ~valid_mask) || arg3 || arg4 || arg5) { + return -TARGET_EINVAL; + } + untagged_addr_mask =3D (arg2 & TARGET_PR_TAGGED_ADDR_ENABLE + ? MAKE_64BIT_MASK(0, 56) : -1); + return 0; + } + case TARGET_PR_GET_TAGGED_ADDR_CTRL: + { + abi_long ret =3D 0; + + if (arg2 || arg3 || arg4 || arg5) { + return -TARGET_EINVAL; + } + if (~untagged_addr_mask !=3D 0) { + ret |=3D TARGET_PR_TAGGED_ADDR_ENABLE; + } + return ret; + } #endif /* AARCH64 */ case PR_GET_SECCOMP: case PR_SET_SECCOMP: --=20 2.25.1 From nobody Tue May 7 13:31:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591331070; cv=none; d=zohomail.com; s=zohoarc; b=V4NoHtNsdBfNX2WDN1/SCSsgELVHoRrrdgXSGnMiFN8fodgzOgvk7/K0e3geq3WytLIUC0PWV89HPkiLL4olVgpRuCjH46A+KuFkpez3E8A+hyGJFfCIWZ/XT4obkgZGy41hlEU13LHRQF5VM1sGnibpF/RA616oTTeWBMPBijQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591331070; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yLR2Th1A4FLiNvF9RrUXZ7U/jaonjCXwdyobyMFPwns=; b=eKExItvQpr3vhCpKYDaDsxm/OEUpYaU+xUBllDOuRMMnclDz1tJqWruu+6T+YDUhNPzIwtvKEkyDTkuGsQnCJxeUriM7jW6i9fkyc0mKCXgp5u0f/s5sAdMXm/epS9Ue1RNNgr1FT748P8nWPtvfyX0RUntjqsX054QkX+wkIfE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591331070140356.75380510867706; Thu, 4 Jun 2020 21:24:30 -0700 (PDT) Received: from localhost ([::1]:38466 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jh3u8-0000LT-It for importer@patchew.org; Fri, 05 Jun 2020 00:24:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39542) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jh3ni-0004ce-5B for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:50 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:37554) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jh3nh-0000lC-8v for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:49 -0400 Received: by mail-pf1-x444.google.com with SMTP id j1so4152767pfe.4 for ; Thu, 04 Jun 2020 21:17:48 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id h15sm5440902pgl.12.2020.06.04.21.17.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 21:17:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yLR2Th1A4FLiNvF9RrUXZ7U/jaonjCXwdyobyMFPwns=; b=GOj5nQRMVmP06GT6WO6lkqGGxSSz4XbxY1w5dXfQDWo37gkmhVehwjctG0mbtz8pU7 3SN07v2kEzJxPXiH7fbB2XxsfjK1eqmoxo5TsOH95XuPSmvu00djLFabYcMKLS3s8tVj rCDSXUSyCzeFOS+x8T0dCg3N5KoqBb0RSg4ctwxko+nHtfSGfm57KdZGtL/aURWjvZrM Ky2h3LluNLZ2tV7ih9wAqDkGcMH+1aHJRWMz4SaybB9pj4Bt6G/yolmkR+kA/GmIAc0U UzxYbX3Qg/6vhH58LA6QYniDQaBu5yLD9I7oIfFyi5n+BKTg+ooRFJsPb32WNNGuioVf 0WBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yLR2Th1A4FLiNvF9RrUXZ7U/jaonjCXwdyobyMFPwns=; b=EKTb79D4WSU8SJ5ChG3/AhF0WEa9sjzkOadLypvG+LUQbzbGJXRme+s/0HGi3Ne+SE MNNWt1VhJRgyiEaK8OlhOi41WplRaSzhuO1HutkM5MsAo8WvN4Os855hHvTdy90m7CwJ tjZFOHJ3teUX9wpgKjYFVqoY2Vkwsf3hTG/8j3We0YwbNC3tfUPzrULsMiHl3AxZZV0D 7FSHJ1tycQauIsHdrS3dfdo1GRTocKKk1FMnJ9/lVoEEV7tnU3+uxrT/8GOcUI70HKhi AcWetrAHSHAPyXckIDj/treDB/E6Surz/we6BgUbjfa/ud7tLwYk5Pz5rcqiWCY7Rfhd U1xQ== X-Gm-Message-State: AOAM531XnT46zSZ0CWnKylxqO4EP844BZLCvY8mhQjJ1dcPMvwgKjHAU wcImW0qgaCh0L4EY5tbtMI5Wx5X8WcY= X-Google-Smtp-Source: ABdhPJyRoo6vgoKYh+l1dwojsZGlRP41MC9/3XeO0h07JmLMEI+JN0x+afzj1w5hDdNFPjzs//zdNw== X-Received: by 2002:a63:a50:: with SMTP id z16mr7448730pgk.162.1591330667378; Thu, 04 Jun 2020 21:17:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 10/17] linux-user/aarch64: Implement PR_MTE_TCF and PR_MTE_TAG Date: Thu, 4 Jun 2020 21:17:26 -0700 Message-Id: <20200605041733.415188-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200605041733.415188-1-richard.henderson@linaro.org> References: <20200605041733.415188-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::444; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x444.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, qemu-arm@nongnu.org, steplong@quicinc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" These prctl fields are required for the function of MTE. Signed-off-by: Richard Henderson --- linux-user/aarch64/target_syscall.h | 9 ++++++ linux-user/syscall.c | 46 +++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/linux-user/aarch64/target_syscall.h b/linux-user/aarch64/targe= t_syscall.h index 5fb0bf4a5d..779ca0c805 100644 --- a/linux-user/aarch64/target_syscall.h +++ b/linux-user/aarch64/target_syscall.h @@ -32,5 +32,14 @@ struct target_pt_regs { #define TARGET_PR_SET_TAGGED_ADDR_CTRL 55 #define TARGET_PR_GET_TAGGED_ADDR_CTRL 56 # define TARGET_PR_TAGGED_ADDR_ENABLE (1UL << 0) +/* MTE tag check fault modes */ +# define TARGET_PR_MTE_TCF_SHIFT 1 +# define TARGET_PR_MTE_TCF_NONE (0UL << TARGET_PR_MTE_TCF_SHIFT) +# define TARGET_PR_MTE_TCF_SYNC (1UL << TARGET_PR_MTE_TCF_SHIFT) +# define TARGET_PR_MTE_TCF_ASYNC (2UL << TARGET_PR_MTE_TCF_SHIFT) +# define TARGET_PR_MTE_TCF_MASK (3UL << TARGET_PR_MTE_TCF_SHIFT) +/* MTE tag inclusion mask */ +# define TARGET_PR_MTE_TAG_SHIFT 3 +# define TARGET_PR_MTE_TAG_MASK (0xffffUL << TARGET_PR_MTE_TAG_SHIF= T) =20 #endif /* AARCH64_TARGET_SYSCALL_H */ diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e4da53c5b3..9cf3ce872d 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -10463,10 +10463,47 @@ static abi_long do_syscall1(void *cpu_env, int nu= m, abi_long arg1, case TARGET_PR_SET_TAGGED_ADDR_CTRL: { abi_ulong valid_mask =3D TARGET_PR_TAGGED_ADDR_ENABLE; + CPUARMState *env =3D cpu_env; + ARMCPU *cpu =3D env_archcpu(env); + + if (cpu_isar_feature(aa64_mte, cpu)) { + valid_mask |=3D TARGET_PR_MTE_TCF_MASK; + valid_mask |=3D TARGET_PR_MTE_TAG_MASK; + } =20 if ((arg2 & ~valid_mask) || arg3 || arg4 || arg5) { return -TARGET_EINVAL; } + + if (cpu_isar_feature(aa64_mte, cpu)) { + switch (arg2 & TARGET_PR_MTE_TCF_MASK) { + case TARGET_PR_MTE_TCF_NONE: + case TARGET_PR_MTE_TCF_SYNC: + case TARGET_PR_MTE_TCF_ASYNC: + break; + default: + return -EINVAL; + } + + /* + * Write PR_MTE_TCF to SCTLR_EL1[TCF0]. + * Note that the syscall values are consistent with hw. + */ + env->cp15.sctlr_el[1] =3D + deposit64(env->cp15.sctlr_el[1], 38, 2, + arg2 >> TARGET_PR_MTE_TCF_SHIFT); + + /* + * Write PR_MTE_TAG to GCR_EL1[Exclude]. + * Note that the syscall uses an include mask, + * and hardware uses an exclude mask -- invert. + */ + env->cp15.gcr_el1 =3D + deposit64(env->cp15.gcr_el1, 0, 16, + ~arg2 >> TARGET_PR_MTE_TAG_SHIFT); + arm_rebuild_hflags(env); + } + untagged_addr_mask =3D (arg2 & TARGET_PR_TAGGED_ADDR_ENABLE ? MAKE_64BIT_MASK(0, 56) : -1); return 0; @@ -10474,6 +10511,8 @@ static abi_long do_syscall1(void *cpu_env, int num,= abi_long arg1, case TARGET_PR_GET_TAGGED_ADDR_CTRL: { abi_long ret =3D 0; + CPUARMState *env =3D cpu_env; + ARMCPU *cpu =3D env_archcpu(env); =20 if (arg2 || arg3 || arg4 || arg5) { return -TARGET_EINVAL; @@ -10481,6 +10520,13 @@ static abi_long do_syscall1(void *cpu_env, int num= , abi_long arg1, if (~untagged_addr_mask !=3D 0) { ret |=3D TARGET_PR_TAGGED_ADDR_ENABLE; } + if (cpu_isar_feature(aa64_mte, cpu)) { + /* See above. */ + ret |=3D (extract64(env->cp15.sctlr_el[1], 38, 2) + << TARGET_PR_MTE_TCF_SHIFT); + ret =3D deposit64(ret, TARGET_PR_MTE_TAG_SHIFT, 16, + ~env->cp15.gcr_el1); + } return ret; } #endif /* AARCH64 */ --=20 2.25.1 From nobody Tue May 7 13:31:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591331108; cv=none; d=zohomail.com; s=zohoarc; b=T813ticfzCCrm6vxC0fPxUHAjyRHnQ5i4p3ukyicMAM+vAqyajlAALOekWFSVNPqOEgny2DQxo8kjdWsVLrCftu80gZGd3x4lAdAzjCLLs3TQsW/94XetkShjt6/KXQg66YVdduUafuf1UkLWlzaqgW3SiSbRJa1ySUgHx7FG6k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591331108; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=p6D0SimXYVXC4E7m3TGAGtyiw9jb/y2AGrQNgRl17pM=; b=MenBQnkGp71Yw9DB2Hl07Ot8ojqQCjw6kNO1IFZmo4Bo1vh0iulA4JRDA1MajbbNfzi9XfFCv7+ocD/YXTmbI+MyX+BA90Z+MrIjRa1Ragd5YLAVUtHQAhgjdvBM1TZ/10D4cD9m2kA7LNnjg3JVaBQ+ZrZwM30/Pab8FIxKe84= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591331108653901.3746209384587; Thu, 4 Jun 2020 21:25:08 -0700 (PDT) Received: from localhost ([::1]:41228 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jh3ul-0001fa-Bw for importer@patchew.org; Fri, 05 Jun 2020 00:25:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jh3nj-0004fi-64 for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:51 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:55971) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jh3ni-0000lO-Da for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:50 -0400 Received: by mail-pj1-x1043.google.com with SMTP id fs4so2053924pjb.5 for ; Thu, 04 Jun 2020 21:17:49 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id h15sm5440902pgl.12.2020.06.04.21.17.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 21:17:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p6D0SimXYVXC4E7m3TGAGtyiw9jb/y2AGrQNgRl17pM=; b=WmdMO5TGkw0TnA4jGXKKBq8eFbnXqVpmqipAkp2psIxZU2FVAlXYOpKCeWGu3u14h5 rqwhBMb01muYtUfwrASzv28qgOClQh9AEmb84yEjxzawxX6Idj8ecE4WGi/PXRVOil1y A2D+oCWfXLnGq8C6ip3DbknI9L1w05tugi7hWQ0CmKAjNYq2Ptg9kwEB85JouCSHtyIL lV7qkPK4RA5407gvDD1W/TluVUQp7940TTYE7iyg1xUkSrGEnRkQpR8oRnLBRPf+rF+0 WQEGfG4jcIa02qbA2Lfn5hS+VHHjrLHmKce7Ll32LMd5uGy1Kzku7iJ/py4vTeri3QOB Pg9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p6D0SimXYVXC4E7m3TGAGtyiw9jb/y2AGrQNgRl17pM=; b=ZarHSLhPrRI+T/bOI2QPXrDZsjWkhyYjtavh0A0CJZwYKGw5LZ3pC0OknTP+vRvjPP cZknj5s+iEaUq9sPMXLgO2d3jaXcfj1mTq/XvOQh+LIhhMNRvBTgJeZJq5nj2CHAb1pO dP77L7A3VauLs+KZXwUkOf9uxkdzWztFbI7bcF3tlU3jhTnKwOscLbp8+7Z5FSRNIVyx pjuF42hZLmE+z1c8hlfo1DQHprVW6tLpCJLbuF4xcXTFY9eXOaIcnByVaIExpBi2jXqt PhNiSkoYb+isiRDAciyZ7dao23Bnv8K42BXvctKLI0Zmck2xfVVWGpyboAKrQYVJ9hPw W4tg== X-Gm-Message-State: AOAM531PVTBhe9b3GTZ+U0zTqqHCwTGYsYGKg7Jda0F2WC5g+QLuLJia /lHq1ms9BHuKjDDqhKfvBtn41VCK39s= X-Google-Smtp-Source: ABdhPJz01C6w+euwWDAv7jpYJ9mjxR+Hda09HLWgpWaMBZseBwOTbQiHXZ/3f2bYB7cvnNsCoXRdBw== X-Received: by 2002:a17:902:564:: with SMTP id 91mr8130642plf.212.1591330668657; Thu, 04 Jun 2020 21:17:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 11/17] linux-user/aarch64: Implement PROT_MTE Date: Thu, 4 Jun 2020 21:17:27 -0700 Message-Id: <20200605041733.415188-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200605041733.415188-1-richard.henderson@linaro.org> References: <20200605041733.415188-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1043; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1043.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, qemu-arm@nongnu.org, steplong@quicinc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Remember the PROT_MTE bit as PAGE_TARGET_2. Otherwise this does not yet have effect. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- include/exec/cpu-all.h | 1 + linux-user/syscall_defs.h | 1 + linux-user/mmap.c | 20 ++++++++++++-------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index 3cac7750e4..7ff10a8b08 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -286,6 +286,7 @@ extern intptr_t qemu_host_page_mask; #endif /* Target-specific bits that will be used via page_get_flags(). */ #define PAGE_TARGET_1 0x0080 +#define PAGE_TARGET_2 0x0100 =20 #if defined(CONFIG_USER_ONLY) void page_dump(FILE *f); diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 36bdafb3f1..f2bfa3b17f 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -1196,6 +1196,7 @@ struct target_winsize { =20 #ifdef TARGET_AARCH64 #define TARGET_PROT_BTI 0x10 +#define TARGET_PROT_MTE 0x20 #endif =20 /* Common */ diff --git a/linux-user/mmap.c b/linux-user/mmap.c index fdd55986a1..b5618c40bd 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -84,18 +84,22 @@ static int validate_prot_to_pageflags(int *host_prot, i= nt prot) | (prot & PROT_EXEC ? PROT_READ : 0); =20 #ifdef TARGET_AARCH64 - /* - * The PROT_BTI bit is only accepted if the cpu supports the feature. - * Since this is the unusual case, don't bother checking unless - * the bit has been requested. If set and valid, record the bit - * within QEMU's page_flags as PAGE_TARGET_1. - */ - if (prot & TARGET_PROT_BTI) { + { ARMCPU *cpu =3D ARM_CPU(thread_cpu); - if (cpu_isar_feature(aa64_bti, cpu)) { + /* + * The PROT_BTI bit is only accepted if the cpu supports the featu= re. + * If set and valid, record the bit within QEMU's page_flags + * as PAGE_TARGET_1. + */ + if ((prot & TARGET_PROT_BTI) && cpu_isar_feature(aa64_bti, cpu)) { valid |=3D TARGET_PROT_BTI; page_flags |=3D PAGE_TARGET_1; } + /* Similarly for the PROT_MTE bit; set PAGE_TARGET_2. */ + if ((prot & TARGET_PROT_MTE) && cpu_isar_feature(aa64_mte, cpu)) { + valid |=3D TARGET_PROT_MTE; + page_flags |=3D PAGE_TARGET_2; + } } #endif =20 --=20 2.25.1 From nobody Tue May 7 13:31:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591330853; cv=none; d=zohomail.com; s=zohoarc; b=kDs0XqWNIqAWRxSjQwenHBBmEaeRp9kZq3aR9sM2iSlqLzXfPoVPctu8tlJTbBLYDpGfr1UszVgDR8lNO+al+OnRWWmwDjK9hwKmdpAeKVrBE7Qyd+t+E0RqzrS0ndrXFNZSaRImse1tE2FEBdLo+dHZJgn7tf8fs9UByhnN7U8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591330853; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OzYHxasinbK12hHGjXt3IY3GTdvR0p0In8jS7714bjc=; b=Fa4LB8dLfsrsqz1AGi/J1y+EZh7T2wJiDsGQU5ACYEAIEBJncxi5zIkkU9hzyHxB5cTy2EvL9M/NOsUIB4xL3BIDzWR3hje8BhDuOGdahV7qQ5903xrFWbJZJZdKySttqhU1rXbjR8a4V6XNjjGLETUAFuw2rgfECLaDQyWdX8c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591330853784412.88552379168243; Thu, 4 Jun 2020 21:20:53 -0700 (PDT) Received: from localhost ([::1]:52478 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jh3qe-0002wc-He for importer@patchew.org; Fri, 05 Jun 2020 00:20:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jh3nk-0004ha-E0 for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:53 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:37554) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jh3nj-0000lf-MB for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:52 -0400 Received: by mail-pf1-x443.google.com with SMTP id j1so4152821pfe.4 for ; Thu, 04 Jun 2020 21:17:51 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id h15sm5440902pgl.12.2020.06.04.21.17.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 21:17:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OzYHxasinbK12hHGjXt3IY3GTdvR0p0In8jS7714bjc=; b=GVjk9AlOfDA0AZJUKWECc3CSMsveyiA9UBLqrsI9qYIAP5YcDDgPKCt1+Vgy6YKY6Z Fv1/jsK7UcR4d9GPSIJyCQO4UCp2N4d6hOxX0wAfvRLa6JQ4wOvblIVTvWF8UGilXXAA 0pjwRpf19EidPalvapvrOUklORbg/MmOQQt2jP6Xh1jIUvQEVXCwdx0evxQqXQus3nsV LP6uuSic/UITigTWMufeWl+7k1JSJOZPHx0xj9Avkfd5/tTFf/sSdRZJaIDF0riPuhTk KyQNKvx8W8GKpIC5FwG6sIBJ4+eifZzXx40EXeF5jT/Fn5viBvZVqX1kBeWYM13RVhcs Wevg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OzYHxasinbK12hHGjXt3IY3GTdvR0p0In8jS7714bjc=; b=N4f9KneHnRt3xA6VxygjhdThoe3oakSv4WzZIhXNoKMHEXdHknC3QcP8bXlTCry5rn lH+DvVPB1f2qJhYavJdF1WOW6w6YACoERzEuhBbnZjt1xnyeInGFDovoOVZP/fcWY7rF /QGRn0HMyyZvFQ00qWxVg33v/LZoAK5J+63G3oUiIEpooFQKuPWSv1DfAybWhwocXdds EUpHsvMw4COQazPbbgXOHCqHrIkMCUd+yTulxBqb0aUwGC7CtBBEBpkOZ2MTP5Os9XhF yiByC4XSYLa0JWNSARvBHVt8GBsMwMyNFirR3YQu7B9rNdc1FnW6BhIP0rYkx3oIqCWj cj8w== X-Gm-Message-State: AOAM532YOqLmPML2W6TYSKVsfyEh4vyoZHTFZ26ohqRq0dV6Y5NW9Tz7 rU0d9/GUkdNuqHIi28wMzhvd5eMGnTQ= X-Google-Smtp-Source: ABdhPJwoZl4kXIFIUzS4JICf1Nr069Ii8sMEWHiLmCCZSm1NX2qAWOHAZFrsXrDCCs5jXPho7JPHeA== X-Received: by 2002:a63:c5a:: with SMTP id 26mr7460938pgm.270.1591330669986; Thu, 04 Jun 2020 21:17:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 12/17] linux-user/aarch64: Pass syndrome to EXC_*_ABORT Date: Thu, 4 Jun 2020 21:17:28 -0700 Message-Id: <20200605041733.415188-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200605041733.415188-1-richard.henderson@linaro.org> References: <20200605041733.415188-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::443; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x443.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, qemu-arm@nongnu.org, steplong@quicinc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" A proper syndrome is required to fill in the proper si_code. Use page_get_flags to determine permission vs translation for user-only. Signed-off-by: Richard Henderson --- linux-user/aarch64/cpu_loop.c | 23 ++++++++++++++++++++--- target/arm/tlb_helper.c | 27 +++++++++++++++++++++------ 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index 3cca637bb9..ce56e15be2 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -75,7 +75,7 @@ void cpu_loop(CPUARMState *env) { CPUState *cs =3D env_cpu(env); - int trapnr; + int trapnr, ec, fsc; abi_long ret; target_siginfo_t info; =20 @@ -116,9 +116,26 @@ void cpu_loop(CPUARMState *env) case EXCP_DATA_ABORT: info.si_signo =3D TARGET_SIGSEGV; info.si_errno =3D 0; - /* XXX: check env->error_code */ - info.si_code =3D TARGET_SEGV_MAPERR; info._sifields._sigfault._addr =3D env->exception.vaddress; + + /* We should only arrive here with EC in {DATAABORT, INSNABORT= }. */ + ec =3D extract32(env->exception.syndrome, 26, 6); + assert(ec =3D=3D 0x24 || ec =3D=3D 0x20); + + /* Both EC have the same format for FSC, or close enough. */ + fsc =3D extract32(env->exception.syndrome, 0, 6); + switch (fsc) { + case 0x04 ... 0x07: /* Translation fault, level {0-3} */ + info.si_code =3D TARGET_SEGV_MAPERR; + break; + case 0x09 ... 0x0b: /* Access flag fault, level {1-3} */ + case 0x0d ... 0x0f: /* Permission fault, level {1-3} */ + info.si_code =3D TARGET_SEGV_ACCERR; + break; + default: + g_assert_not_reached(); + } + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); break; case EXCP_UNALIGNED: diff --git a/target/arm/tlb_helper.c b/target/arm/tlb_helper.c index d4e6d37f4f..35d84ac24f 100644 --- a/target/arm/tlb_helper.c +++ b/target/arm/tlb_helper.c @@ -10,8 +10,6 @@ #include "internals.h" #include "exec/exec-all.h" =20 -#if !defined(CONFIG_USER_ONLY) - static inline uint32_t merge_syn_data_abort(uint32_t template_syn, unsigned int target_el, bool same_el, bool ea, @@ -51,6 +49,8 @@ static inline uint32_t merge_syn_data_abort(uint32_t temp= late_syn, return syn; } =20 +#if !defined(CONFIG_USER_ONLY) + static void QEMU_NORETURN arm_deliver_fault(ARMCPU *cpu, vaddr addr, MMUAccessType access_type, int mmu_idx, ARMMMUFaultInfo *= fi) @@ -138,13 +138,28 @@ bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, in= t size, ARMCPU *cpu =3D ARM_CPU(cs); =20 #ifdef CONFIG_USER_ONLY + int flags, fsc, exc; + unsigned syn; + cpu->env.exception.vaddress =3D address; - if (access_type =3D=3D MMU_INST_FETCH) { - cs->exception_index =3D EXCP_PREFETCH_ABORT; + + flags =3D page_get_flags(useronly_clean_ptr(address)); + if (flags & PAGE_VALID) { + fsc =3D 0xf; /* permission fault, level 3 */ } else { - cs->exception_index =3D EXCP_DATA_ABORT; + fsc =3D 0x7; /* translation fault, level 3 */ } - cpu_loop_exit_restore(cs, retaddr); + + cpu_restore_state(cs, retaddr, true); + if (access_type =3D=3D MMU_INST_FETCH) { + exc =3D EXCP_PREFETCH_ABORT; + syn =3D syn_insn_abort(0, 0, 0, fsc); + } else { + exc =3D EXCP_DATA_ABORT; + syn =3D merge_syn_data_abort(cpu->env.exception.syndrome, 1, 0, 0,= 0, + access_type =3D=3D MMU_DATA_STORE, fsc); + } + raise_exception(&cpu->env, exc, syn, 1); #else hwaddr phys_addr; target_ulong page_size; --=20 2.25.1 From nobody Tue May 7 13:31:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591330961; cv=none; d=zohomail.com; s=zohoarc; b=X+B4W8FVnxf3wgmqFmuWpIBW/V/s0fTZ2KIeRH4homhvBWiXS4q399WCOHtop+vzmQ0Tgrgjy1anL2YMVEbemQUCf6+Q1AKRLkyI9SjbJd08+/6OUo+s4wFcQAeu/rk2kPPvP1Di4IcPNkK2ZBCHkc1TEB0pdsUvOYBNGPu7EJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591330961; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VnwDYHyJTXcVKd4YU4u1JIC2YJpF3XkI8XH4jG+QmBM=; b=W2GGYGi2kWT/NHY/Ti933xF/bRocY/6PtN5ldg6iBB2CVJsEKTi1vBXDgtTD30wMSNf9MEAbrhWT+axdcsI5BqNibwNUU/3pRoANauASXSCVy1m7wYxNxOmz9u3AYadV77G7TL+j8LtNhjXI9SWTwUtpz3UqbI8AxMxs35+SXiw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591330961974459.5430314004369; Thu, 4 Jun 2020 21:22:41 -0700 (PDT) Received: from localhost ([::1]:32832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jh3sO-0006R7-N8 for importer@patchew.org; Fri, 05 Jun 2020 00:22:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jh3nm-0004jI-8u for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:54 -0400 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]:40215) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jh3nl-0000m5-AP for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:53 -0400 Received: by mail-pj1-x1041.google.com with SMTP id s88so2179789pjb.5 for ; Thu, 04 Jun 2020 21:17:52 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id h15sm5440902pgl.12.2020.06.04.21.17.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 21:17:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VnwDYHyJTXcVKd4YU4u1JIC2YJpF3XkI8XH4jG+QmBM=; b=O4UYiAV9Ibj4ddqY35TKWtkunv4B9sYlB+YwK+UeIUdNLEv92cT3NaN8GmWM9alH7Y 4lKUNk/gFpu5W8/DGaIewYGKBSQdeMv+RlHFcViD22IRUt3bZ24V3yy/DETld18qojHQ HdFY3TuTBfnXfRVzT0g8ZubDfIbhJk0U20eaRBcF/YPTWlqy/Bz3Pl/rdmI6DI6inLUT zcdNeDYWvOGdnr8+dlRr/QOgtdkpkqfl4fQxPuuKat3Kb0M9qBvdtkE1LSsYD12uJXYX EDQUMdGW/euqhY0eNbtefdgx+VUHHk83bJcsLS2A6MhNFKA4uFXw2t3Q7GDeA1HcyLvj xPpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VnwDYHyJTXcVKd4YU4u1JIC2YJpF3XkI8XH4jG+QmBM=; b=ROhheJUAVy1Ad3TcQXMqtq+jETMWlDuL9FkaVH5ee1/SdSG2AJwee6RJcDZMYdixhI 41LPuUEyqYFUlW71q5lkVAU1s5WnF00Gq2UJq52H/nu8b7giEz/n4qR01eZV+qDXWjbb Owff1EVqF+MHV2DqoqEANEZywvetlsZRMLfdUCUQo5U1zcTUX/nOdooh7qCf5ECA8fuo RmARxiPMbOJX1YJ942Df0G8/tAnbC7XcflIOTjxmX+7JlCLtLjGoX9Ow+AkwHv4quKsx cydZ3UNcqRShOmX1+vFORa5f2oOL6uOOmlfZzZjljC8tu1T9nkySR/5gvSD9AQp1To6f PJXg== X-Gm-Message-State: AOAM531bhW7Irg3HZMQsnR8wEkcLT4uDFDOsJpcNI4ALClr9dC3Su05c MvlVbVpsfM85IrIKfc/DVyJVx5PVtqs= X-Google-Smtp-Source: ABdhPJygvBGvbkJQaomvWIqZAV2+yzzElU7Hys64+HsqsLKL/tkfbbE5f7yyMeCSHdObXbSKGvyoPQ== X-Received: by 2002:a17:90a:c258:: with SMTP id d24mr761390pjx.137.1591330671158; Thu, 04 Jun 2020 21:17:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 13/17] linux-user/aarch64: Signal SEGV_MTESERR for sync tag check fault Date: Thu, 4 Jun 2020 21:17:29 -0700 Message-Id: <20200605041733.415188-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200605041733.415188-1-richard.henderson@linaro.org> References: <20200605041733.415188-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1041; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1041.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, qemu-arm@nongnu.org, steplong@quicinc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- linux-user/aarch64/target_signal.h | 2 ++ linux-user/aarch64/cpu_loop.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/linux-user/aarch64/target_signal.h b/linux-user/aarch64/target= _signal.h index ddd73169f0..777fb667fe 100644 --- a/linux-user/aarch64/target_signal.h +++ b/linux-user/aarch64/target_signal.h @@ -21,5 +21,7 @@ typedef struct target_sigaltstack { =20 #include "../generic/signal.h" =20 +#define TARGET_SEGV_MTESERR 9 /* Synchronous ARM MTE exception */ + #define TARGET_ARCH_HAS_SETUP_FRAME #endif /* AARCH64_TARGET_SIGNAL_H */ diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index ce56e15be2..41a68a57bc 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -132,6 +132,9 @@ void cpu_loop(CPUARMState *env) case 0x0d ... 0x0f: /* Permission fault, level {1-3} */ info.si_code =3D TARGET_SEGV_ACCERR; break; + case 0x11: /* Synchronous Tag Check Fault */ + info.si_code =3D TARGET_SEGV_MTESERR; + break; default: g_assert_not_reached(); } --=20 2.25.1 From nobody Tue May 7 13:31:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591331093; cv=none; d=zohomail.com; s=zohoarc; b=dtGMAb8Zgr0SupdOcwYStfR2PomXe+/RoYtp8EYsDMQhDYRFdgiX4EI+lWRvXUYVEUl8zL3gA6AU+jCBmoE2gOGLwEKOVc+gn8fC82/lv6/jD+/B/+ncJGpMWzFy8Yr5cdwGnnlBTjZbpLwnPM1xmSZp049/BddCbwY7cVawv2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591331093; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=025+D4aoylrwlotsdqqyp7BRSM6nAeDFcADkgg9A3QU=; b=XMWUDbzPCZ46XeFoWvAadtIs3ipBZzRkPo/8l01jTfGnlkrzbnyOo0SCvacfi3cSouJ/SzRE3jpoGS6v7WO60jmRcpHuIoOGtzW7cUzx91m94f3QxYixMlmqfzJiDKJjjkhYfyECeciTpiIHGmhCCxIT/Gmqhkh7Rvn8PAFW7Ok= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591331093524272.36247754358203; Thu, 4 Jun 2020 21:24:53 -0700 (PDT) Received: from localhost ([::1]:39814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jh3uW-00010Z-1K for importer@patchew.org; Fri, 05 Jun 2020 00:24:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jh3nn-0004lI-Gz for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:56 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:46563) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jh3nm-0000mJ-P1 for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:55 -0400 Received: by mail-pf1-x443.google.com with SMTP id b16so4295086pfi.13 for ; Thu, 04 Jun 2020 21:17:54 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id h15sm5440902pgl.12.2020.06.04.21.17.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 21:17:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=025+D4aoylrwlotsdqqyp7BRSM6nAeDFcADkgg9A3QU=; b=yrmPfvKuRo6BzO7M2VRSldilbgVlDVJW2mbTb2+GXbbfhfFQoAOzCcnnmzH0n7yAOW Zz+cnubYo3iDBzL23iRDah3EXvsFir0VrQ5lx1TFTsmDxW2ASaGYvUWmBpRc7gqqFQST zApQDW2GbFDJRQmT3I+vWP3ANWVKxQh1ChLkVHAwPvGr9jC4JTbYoaIJl1hrZ3cjCA+R MbZh7mGPvwM260Yvyoujzp0IsyZ26FxVHyx26R7RyVmdyamE7zqVilLa71KGphCdBzZT C+/+80CxBindWcfGxebbTINgLZ8dqdz/wy+0k3aRnkkHiPEu4/PY31vA93YAOJGl/1XS meRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=025+D4aoylrwlotsdqqyp7BRSM6nAeDFcADkgg9A3QU=; b=MMZnuruYwPBKF9uzbgjXd9vmHW9S8QTq1u4mPwaCh3xiIWX1Yqo/RmE99NE5Xx5Jrj d7PXC2Qk4AOvqGTysYfxOBY8ELygUus7K7FREaS674GAhhudOaJzkAEDmUShon8vuROO ZOD2O65e5FeapyX4R3qyzoVngL1YSnBRw4MngHwsp9ftGTfcZTU280lCwZeEJ399ivOm zxjVPR/37murvl0Lsr59LCHKjqQP76uHtYEXhF3BjQKQ+Z8ULeIlxvkxSTolCvFyOab6 0KCE1a0qNjZVOblFQ2eHrOqQRqMvctjeynX1JdJGN5DWBZTuZRanniGMmUKFJqoBj1A+ 9nig== X-Gm-Message-State: AOAM531EYNWIIrRGEktyPb+Ca6LRmq66ojw25mEQmjbnRLKFO7rWPeie cH0eSPTFWUDgoP7ZTUs9KXL2EoK+C5s= X-Google-Smtp-Source: ABdhPJzQFJX5FVFVnGJvPLAH7/XunNJ0vh/wHsOHkegTGR9wLp/FbFRsilSZwIbC6OF49ASvns47Ww== X-Received: by 2002:a62:c185:: with SMTP id i127mr8023028pfg.132.1591330673199; Thu, 04 Jun 2020 21:17:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 14/17] linux-user/aarch64: Signal SEGV_MTEAERR for async tag check error Date: Thu, 4 Jun 2020 21:17:30 -0700 Message-Id: <20200605041733.415188-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200605041733.415188-1-richard.henderson@linaro.org> References: <20200605041733.415188-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::443; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x443.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, qemu-arm@nongnu.org, steplong@quicinc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- linux-user/aarch64/target_signal.h | 1 + linux-user/aarch64/cpu_loop.c | 34 +++++++++++++++++++++--------- target/arm/mte_helper.c | 10 +++++++++ 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/linux-user/aarch64/target_signal.h b/linux-user/aarch64/target= _signal.h index 777fb667fe..18013e1b23 100644 --- a/linux-user/aarch64/target_signal.h +++ b/linux-user/aarch64/target_signal.h @@ -21,6 +21,7 @@ typedef struct target_sigaltstack { =20 #include "../generic/signal.h" =20 +#define TARGET_SEGV_MTEAERR 8 /* Asynchronous ARM MTE error */ #define TARGET_SEGV_MTESERR 9 /* Synchronous ARM MTE exception */ =20 #define TARGET_ARCH_HAS_SETUP_FRAME diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index 41a68a57bc..1b2f2b4239 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -71,6 +71,21 @@ put_user_u16(__x, (gaddr)); \ }) =20 +static bool check_mte_async_fault(CPUARMState *env, target_siginfo_t *info) +{ + if (likely(env->cp15.tfsr_el[0] =3D=3D 0)) { + return false; + } + + env->cp15.tfsr_el[0] =3D 0; + info->si_signo =3D TARGET_SIGSEGV; + info->si_errno =3D 0; + info->_sifields._sigfault._addr =3D 0; + info->si_code =3D TARGET_SEGV_MTEAERR; + queue_signal(env, info->si_signo, QEMU_SI_FAULT, info); + return true; +} + /* AArch64 main loop */ void cpu_loop(CPUARMState *env) { @@ -87,15 +102,13 @@ void cpu_loop(CPUARMState *env) =20 switch (trapnr) { case EXCP_SWI: - ret =3D do_syscall(env, - env->xregs[8], - env->xregs[0], - env->xregs[1], - env->xregs[2], - env->xregs[3], - env->xregs[4], - env->xregs[5], - 0, 0); + if (check_mte_async_fault(env, &info)) { + ret =3D -TARGET_ERESTARTSYS; + } else { + ret =3D do_syscall(env, env->xregs[8], env->xregs[0], + env->xregs[1], env->xregs[2], env->xregs[= 3], + env->xregs[4], env->xregs[5], 0, 0); + } if (ret =3D=3D -TARGET_ERESTARTSYS) { env->pc -=3D 4; } else if (ret !=3D -TARGET_QEMU_ESIGRETURN) { @@ -103,7 +116,8 @@ void cpu_loop(CPUARMState *env) } break; case EXCP_INTERRUPT: - /* just indicate that signals should be handled asap */ + /* Just indicate that signals should be handled asap. */ + check_mte_async_fault(env, &info); break; case EXCP_UDEF: info.si_signo =3D TARGET_SIGILL; diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c index b15fa665df..835b6d1ded 100644 --- a/target/arm/mte_helper.c +++ b/target/arm/mte_helper.c @@ -542,6 +542,16 @@ static void mte_check_fail(CPUARMState *env, int mmu_i= dx, select =3D 0; } env->cp15.tfsr_el[el] |=3D 1 << select; +#ifdef CONFIG_USER_ONLY + /* + * Stand in for a timer irq, setting _TIF_MTE_ASYNC_FAULT, + * which then sends a SIGSEGV when the thread is next scheduled. + * This cpu will return to the main loop at the end of the TB, + * which is rather sooner than "normal". But the alternative + * is waiting until the next syscall. + */ + qemu_cpu_kick(env_cpu(env)); +#endif break; =20 default: --=20 2.25.1 From nobody Tue May 7 13:31:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591331161; cv=none; d=zohomail.com; s=zohoarc; b=Q2yd0opyq9ZhYXKDxPilnvhRdI45NUgP08QCRKz3eadacbAGK8y3Vw44nKbsv0IjrmbrOJ7KhIN4p6vfMRhnteCw85X9pd2/nqivnTI0UHfcWyjac4+mAxRLaEWjmiofhfMPTJ3CJpg46/gEDQZTX+zfRayF6fMdyhRzXsmS71s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591331161; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CDahIOixg8N2JHR7Ek8lGA826Cs5BmS4mXRyzAL5jqQ=; b=AJTD6SG9VJVALYRO2j9X5lCopTbF7sto85uFXgz39FOYgBzonZs27e7KB1K0scJjvNkjBxew/INb+BV/Wtp5inopujN11Mg7s8AcOHiF8rcaIknxYJquw8OGKY0ACQ8ull5JDGAOdjZsJy5by07lxjEdxf6oM0QB3FVePuV9A6U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591331160993314.24161068387446; Thu, 4 Jun 2020 21:26:00 -0700 (PDT) Received: from localhost ([::1]:45406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jh3vb-0003Rl-Q6 for importer@patchew.org; Fri, 05 Jun 2020 00:25:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39600) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jh3no-0004m7-JY for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:56 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:40559) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jh3nn-0000mc-Ug for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:56 -0400 Received: by mail-pf1-x444.google.com with SMTP id s23so2989729pfh.7 for ; Thu, 04 Jun 2020 21:17:55 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id h15sm5440902pgl.12.2020.06.04.21.17.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 21:17:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CDahIOixg8N2JHR7Ek8lGA826Cs5BmS4mXRyzAL5jqQ=; b=Qzvmb+yr6V0rS9fXM7NM1NdR+u0oIf5AZbDsKcxKqGQtlvVdnkS9tfGiwMCoyvdY99 taQ9wK2VfVc1+0Rk8wy0eTrK/oS6pizdvQbgLvTwL0WVP80PL8OlRNKC0aKpUnhaQIEy l1cTfvDQNbYGDLvEJfZcF1QdS7F0TwfffRpcBgHyAsY0PNLL5BP+pTJ2riG+3ygitnFq 0NdYGj5hMpO+ktUHAu4R+on5nL5fxaqlHHSQuI0CNMEHG3kRuPYldQwhpI6HOPFh8jYM 4fDyq3sD9eLNW/zmHR4pjAbw1ut+j5vVYgDaynY3J12HBNOAM7U2jZGvUq+eQuHgGNkJ IdYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CDahIOixg8N2JHR7Ek8lGA826Cs5BmS4mXRyzAL5jqQ=; b=ZbiTMrnhJTryCbkIdd6udFJwRD1KPi/hIU34/Y8r5Em0IGYm37eJ9dOUBdZJ22R5Ie 9+smtdjudBQqiJhd5Gu5shgvJ1XnQBcMIjRqjdk6tgtzgbM1bezddauCwXbGf1AuXCPS CN/lXhZ2PrPRC2e2lAeDlL/i0PZB8mzX8OpvYXoOAcCegPmgRRyFkhOVFgIZ6rVK8zKM iofRQyTrc7km2AeQxvuuxgSWMZuy56HZnDKLW9x+vXc1ZQymEd5H4AUX2cClq/Gx0GFu kVx2pxYZSZ82NaW2sKQNxVWzygJQQjAVX2SNYORwrrGuGTUUVYavFOQJi7fjfAhNQvuv 7giA== X-Gm-Message-State: AOAM533CmVbplumLdFXSPVGF8IFfpm7Byr3cSvJkNJiAhy8gDq3u9tN4 Yt6OUXBdo46sjxXy/SmRV4l3m9h3n5E= X-Google-Smtp-Source: ABdhPJx6IdCj2qX9lo7rozUN//LYEpX56q5biPL0Wjk/budDyzjIV/0Oop+UeQ4N6RSEWJQYlWpHPQ== X-Received: by 2002:aa7:84cc:: with SMTP id x12mr7437645pfn.235.1591330674397; Thu, 04 Jun 2020 21:17:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 15/17] target/arm: Add allocation tag storage for user mode Date: Thu, 4 Jun 2020 21:17:31 -0700 Message-Id: <20200605041733.415188-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200605041733.415188-1-richard.henderson@linaro.org> References: <20200605041733.415188-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::444; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x444.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, qemu-arm@nongnu.org, steplong@quicinc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Use the now-saved PAGE_ANON and PAGE_TARGET_2 bits, and the per-page saved data. Signed-off-by: Richard Henderson --- target/arm/mte_helper.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c index 835b6d1ded..0911cebd36 100644 --- a/target/arm/mte_helper.c +++ b/target/arm/mte_helper.c @@ -76,8 +76,33 @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int= ptr_mmu_idx, int tag_size, uintptr_t ra) { #ifdef CONFIG_USER_ONLY - /* Tag storage not implemented. */ - return NULL; + uint64_t clean_ptr =3D useronly_clean_ptr(ptr); + int flags =3D page_get_flags(clean_ptr); + uint8_t *tags; + uintptr_t index; + + if (!(flags & (ptr_access =3D=3D MMU_DATA_STORE ? PAGE_WRITE : PAGE_RE= AD))) { + /* SIGSEGV */ + arm_cpu_tlb_fill(env_cpu(env), ptr, ptr_size, ptr_access, + ptr_mmu_idx, false, ra); + g_assert_not_reached(); + } + + /* Require both MAP_ANON and PROT_MTE for the page. */ + if (!(flags & PAGE_ANON) || !(flags & PAGE_TARGET_2)) { + return NULL; + } + + tags =3D page_get_target_data(clean_ptr); + if (tags =3D=3D NULL) { + size_t alloc_size =3D TARGET_PAGE_SIZE >> (LOG2_TAG_GRANULE + 1); + tags =3D page_alloc_target_data(clean_ptr, alloc_size); + assert(tags !=3D NULL); + } + + index =3D extract32(ptr, LOG2_TAG_GRANULE + 1, + TARGET_PAGE_BITS - LOG2_TAG_GRANULE - 1); + return tags + index; #else uintptr_t index; CPUIOTLBEntry *iotlbentry; --=20 2.25.1 From nobody Tue May 7 13:31:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591331197; cv=none; d=zohomail.com; s=zohoarc; b=LiYLTWAE84ij7UQEow1MsOB2DkAAqMzRQQKO9ykjHsjGY5/dPVTy4D+SOtesLEiuxrBSxh5CGDxy42ln01BV4L2En4PxldcFOa/LJ0hXMUL51/CcHsyJpxy+rfK3lLNiUTm9t7lgxboiJDz5a6yhlc+lB5ncbScSDLWaF8BJRME= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591331197; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7wl+QdYCs/b+nFYwpri9epwwg1rNtdW9XylmaArLSo0=; b=Xi2fyoeLafjRJcHIWlWmlC7yfPwm6Kso3ciHfd/brg2vRGncpvdSLdmIrURCccJSBY9cVrIYABc4jQR2t1zMGkAlh1KVI2xlKzxcUkYcB13fGLrKMGPH9/pZKxDzvw5bognh1nU1UkSDNOJiM/w+hgQzUVx9XzBXc1W7sKw2FJM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591331197071979.0727598280678; Thu, 4 Jun 2020 21:26:37 -0700 (PDT) Received: from localhost ([::1]:47044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jh3wB-000476-U4 for importer@patchew.org; Fri, 05 Jun 2020 00:26:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jh3nq-0004oG-Bm for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:58 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:38934) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jh3np-0000mw-G9 for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:58 -0400 Received: by mail-pj1-x1043.google.com with SMTP id h95so2181254pje.4 for ; Thu, 04 Jun 2020 21:17:56 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id h15sm5440902pgl.12.2020.06.04.21.17.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 21:17:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7wl+QdYCs/b+nFYwpri9epwwg1rNtdW9XylmaArLSo0=; b=cQxyorMAU8+1QNUYtQhzCFjW1u4xVBdmi2WxWjOAJHTlfkkzJqHvbU+HiDOohvwOct e+nHWOqSpnXOeSORC61ph8dLA+DlEfTX2XTz9avKNWGdeWkLdhfu5H64IT6WDwgJuKU8 3Kt5tIqD02fpdHx01TvZsQxPqhatIuQ+zjeGY3tjJ0TNN6nRI8uEK6ILwfyY0K1fx4JT cQ3Ht7PTuTQ9e4758AgWQHAJ83Wd8wfLvskxcvx05UD16kLKst9RFLGtAlPJH5ODt1y9 sSErkbnQke6zY/FGpNwFcozrocgt608PdQdbqacubq5PkwglvMUtxTfWgOiY5z8rS4X9 e6HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7wl+QdYCs/b+nFYwpri9epwwg1rNtdW9XylmaArLSo0=; b=Au/lKkpRJtsbeqt+nNLMW2d7NqPWttAkBWPhTvsakhiTUqjJEJo5JAyeIGmA5XGKHS pR90WeV3Weg7mjM8CsMbqUTHVVk7mWu9aSKQesZ8Uq+0v9rAK1ukHtJndpX6/iloSVLG gIL8pKZ4ky0tSGfztKpQM/3TMEIWJ+fedJQPoaNba2pItnCFS5X/F+SjYfZF5g5bruIa 6T027fH05ryO50syTaL19KiVyawodCWYZ/umB3/fw9Ev5jD1zrJOSeY1CpVJdpoqusR7 OARZmTN57Fy6Q9CtF9gK6l9kn1A+226k2WB0UJ3QuChsdFkueEP8xTo7XU6PWiwH+hr1 2phw== X-Gm-Message-State: AOAM530ZjXkD/GC6GhyOrHA2qbvPt/X0WtoWUNxseT/yERgPGGIJk+hq yORqOJjqvAyW7pH0GljKcIQtpXsG37w= X-Google-Smtp-Source: ABdhPJzv1aUT9Tup+DxWyiwWwBt823/qt6/B2Q4LXY7ZoXJGBef4Ak/vuRRMAh3J4PNmJ+9PKwWfyw== X-Received: by 2002:a17:902:b603:: with SMTP id b3mr8153031pls.1.1591330675623; Thu, 04 Jun 2020 21:17:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 16/17] target/arm: Enable MTE for user-only Date: Thu, 4 Jun 2020 21:17:32 -0700 Message-Id: <20200605041733.415188-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200605041733.415188-1-richard.henderson@linaro.org> References: <20200605041733.415188-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1043; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1043.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, qemu-arm@nongnu.org, steplong@quicinc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- target/arm/cpu.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 37b7cc2c9c..6395918524 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -39,6 +39,7 @@ #include "kvm_arm.h" #include "disas/capstone.h" #include "fpu/softfloat.h" +#include "qemu/guest-random.h" =20 static void arm_cpu_set_pc(CPUState *cs, vaddr value) { @@ -191,6 +192,22 @@ static void arm_cpu_reset(DeviceState *dev) /* Enable all PAC keys. */ env->cp15.sctlr_el[1] |=3D (SCTLR_EnIA | SCTLR_EnIB | SCTLR_EnDA | SCTLR_EnDB); + /* Enable MTE */ + if (cpu_isar_feature(aa64_mte, cpu)) { + /* Enable tag access, but leave TCF0 as No Effect (0). */ + env->cp15.sctlr_el[1] |=3D SCTLR_ATA0; + /* + * Exclude all tags, so that tag 0 is always used. + * This corresponds to Linux current->thread.gcr_incl =3D 0. + */ + env->cp15.gcr_el1 =3D 0xffff; + /* If RGSR =3D=3D 0, NextRandomTagBit will always produce 0. = */ + do { + qemu_guest_getrandom_nofail(&env->cp15.rgsr_el1, + sizeof(env->cp15.rgsr_el1)); + env->cp15.rgsr_el1 &=3D 0xffff0fu; + } while (env->cp15.rgsr_el1 =3D=3D 0); + } /* and to the FP/Neon instructions */ env->cp15.cpacr_el1 =3D deposit64(env->cp15.cpacr_el1, 20, 2, 3); /* and to the SVE instructions */ --=20 2.25.1 From nobody Tue May 7 13:31:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591331282; cv=none; d=zohomail.com; s=zohoarc; b=B9plyKFgiAwFJayy72AeQJxvdmE++9aTLj5h1k/w78weRq49te9Dh0uGAgQHQyqO0mGOaLalZM8HhE5/9v6lh8JDa4phsZHWejeq2ZikjRs3B6dRq4zRyVzZ9NrgH2Is5MwLISLkJJ5E3tnsglMrkZpdrubd71F396r9AidWxLA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591331282; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Kb6rkAj53RRMvC2rZIPmdOIeGY5NNQOnyCUHmHsi04g=; b=cnwj0UNw+TMfots37vD2ijWm1Yp2CnZzHcgj5NhBiOhrNIUz5JW8i9EXTYHmt+jXwjycqo7mkmDkLsnyn2HHzs4QB7QutqWft9tEnd5+g+351iRZcIoiq6FCRFJrlHsJ0JM309SEa0g8V9xk1G9i+qAqrSs1gIqQcRdU+9RlRSs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159133128286072.5141986282174; Thu, 4 Jun 2020 21:28:02 -0700 (PDT) Received: from localhost ([::1]:50096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jh3xZ-0005UU-Mq for importer@patchew.org; Fri, 05 Jun 2020 00:28:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jh3ns-0004q4-0G for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:18:00 -0400 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]:53908) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jh3nq-0000nF-Nl for qemu-devel@nongnu.org; Fri, 05 Jun 2020 00:17:59 -0400 Received: by mail-pj1-x1044.google.com with SMTP id i12so2055966pju.3 for ; Thu, 04 Jun 2020 21:17:58 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id h15sm5440902pgl.12.2020.06.04.21.17.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 21:17:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Kb6rkAj53RRMvC2rZIPmdOIeGY5NNQOnyCUHmHsi04g=; b=yvH8g8dfduLa1IpIp3sKKOzLXGe/K6K2dXH9Ga8tayx7j68WrkKCZGMaYxhBAq3dUl WUXs+tBf1IwPtwK29PrMEBPS2Z6CY+/duUtFRMnS3Bd1aKxBMlprfS76J7qDErNg0ag0 /kKG6iAx+cTcbENv2mTP8k3M39cujyLwIZs/e98FpvOkgBCi/BpOgzdAYmrsFOXvwZBl NX8x1XnLp48IfyZjkFgvlamDu9YbE3WsSdMAn0LpTwAfsAYgYSpmadxbQFpbJtQZyQBf FCLxqTiQ/iKRTJlMsGO1dSn3Nu6TgP2a17s7O4DDBiZqR4rWBfsFDYJYy8llXuRnrBpY tsHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Kb6rkAj53RRMvC2rZIPmdOIeGY5NNQOnyCUHmHsi04g=; b=FEUYjgXLg9+9r2I/9Wn89v28ZT+Z0n05yJ87azfcbnTszQRM2Y/pXv9BPRpMEneggq EK0mmJr87llBRml7FR9CYnqe3Fe6aK6MBz3F6yeOovT9tPuoHhpS7PfFDox0BZegerQK gXXg+p2Jr7ZpNcqYa4BQCbHUVEorBc/+EjDiFmh914Lc7tXU8NC5v71BgjdFKA9ahHMb Icj09gU7WiciFHjZgZVEZISWW7wu5+l54WCjN8P++9oV4kcP2CddH7Gqgi/S6X0s1aJ7 CuytX0UEe+Ugdhrh26bnBv5sXuOnmqxjxuV4h/K70Wj6mGRw7nyKIlaLM5Zx9lz0NIZM H3mQ== X-Gm-Message-State: AOAM530Zirwfkp3zN1lmvJWuHNrY3x7tv1mRXSlsmj2zGMzW4712QAcK JaGxU59ko2EdlNfzOISW3/v1TtDbFPM= X-Google-Smtp-Source: ABdhPJwL3M7Aotp+nUIgfHxyq/UnQJBFH1ub4HHA++UdleqHrQaLOzVdEqrW1j4A9LSuh1gaJAUuIA== X-Received: by 2002:a17:902:b718:: with SMTP id d24mr7690094pls.185.1591330676832; Thu, 04 Jun 2020 21:17:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 17/17] tests/tcg/aarch64: Add mte smoke tests Date: Thu, 4 Jun 2020 21:17:33 -0700 Message-Id: <20200605041733.415188-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200605041733.415188-1-richard.henderson@linaro.org> References: <20200605041733.415188-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1044; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1044.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.maydell@linaro.org, qemu-arm@nongnu.org, steplong@quicinc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- tests/tcg/aarch64/mte.h | 54 +++++++++++++++++++++++++++++++ tests/tcg/aarch64/mte-1.c | 25 ++++++++++++++ tests/tcg/aarch64/mte-2.c | 42 ++++++++++++++++++++++++ tests/tcg/aarch64/mte-3.c | 47 +++++++++++++++++++++++++++ tests/tcg/aarch64/Makefile.target | 4 +++ 5 files changed, 172 insertions(+) create mode 100644 tests/tcg/aarch64/mte.h create mode 100644 tests/tcg/aarch64/mte-1.c create mode 100644 tests/tcg/aarch64/mte-2.c create mode 100644 tests/tcg/aarch64/mte-3.c diff --git a/tests/tcg/aarch64/mte.h b/tests/tcg/aarch64/mte.h new file mode 100644 index 0000000000..7bcc416e6a --- /dev/null +++ b/tests/tcg/aarch64/mte.h @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef PR_SET_TAGGED_ADDR_CTRL +# define PR_SET_TAGGED_ADDR_CTRL 55 +#endif +#ifndef PR_TAGGED_ADDR_ENABLE +# define PR_TAGGED_ADDR_ENABLE (1UL << 0) +#endif +#ifndef PR_MTE_TCF_SHIFT +# define PR_MTE_TCF_SHIFT 1 +# define PR_MTE_TCF_NONE (0UL << PR_MTE_TCF_SHIFT) +# define PR_MTE_TCF_SYNC (1UL << PR_MTE_TCF_SHIFT) +# define PR_MTE_TCF_ASYNC (2UL << PR_MTE_TCF_SHIFT) +# define PR_MTE_TAG_SHIFT 3 +#endif + +#ifndef PROT_MTE +# define PROT_MTE 0x20 +#endif + +#ifndef SEGV_MTEAERR +# define SEGV_MTEAERR 8 +# define SEGV_MTESERR 9 +#endif + +static void enable_mte(int tcf) +{ + int r =3D prctl(PR_SET_TAGGED_ADDR_CTRL, + PR_TAGGED_ADDR_ENABLE | tcf | (0xfffe << PR_MTE_TAG_SHIF= T), + 0, 0, 0); + if (r < 0) { + perror("PR_SET_TAGGED_ADDR_CTRL"); + exit(2); + } +} + +static void *alloc_mte_page(void) +{ + void *p =3D mmap(NULL, getpagesize(), + PROT_READ | PROT_WRITE | PROT_MTE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (p =3D=3D MAP_FAILED) { + perror("mmap PROT_MTE"); + exit(2); + } + return p; +} diff --git a/tests/tcg/aarch64/mte-1.c b/tests/tcg/aarch64/mte-1.c new file mode 100644 index 0000000000..e62c842e85 --- /dev/null +++ b/tests/tcg/aarch64/mte-1.c @@ -0,0 +1,25 @@ +/* + * Memory tagging, basic pass cases. + */ + +#include "mte.h" + +int main(int ac, char **av) +{ + int *p0, *p1, *p2; + long c; + + enable_mte(PR_MTE_TCF_NONE); + p0 =3D alloc_mte_page(); + + asm("irg %0,%1,%2" : "=3Dr"(p1) : "r"(p0), "r"(1)); + assert(p1 !=3D p0); + asm("subp %0,%1,%2" : "=3Dr"(c) : "r"(p0), "r"(p1)); + assert(c =3D=3D 0); + + asm("stg %0, [%0]" : : "r"(p1)); + asm("ldg %0, [%1]" : "=3Dr"(p2) : "r"(p0), "0"(p0)); + assert(p1 =3D=3D p2); + + return 0; +} diff --git a/tests/tcg/aarch64/mte-2.c b/tests/tcg/aarch64/mte-2.c new file mode 100644 index 0000000000..68b5708462 --- /dev/null +++ b/tests/tcg/aarch64/mte-2.c @@ -0,0 +1,42 @@ +/* + * Memory tagging, basic fail cases. + */ + +#include "mte.h" + +void pass(int sig, siginfo_t *info, void *uc) +{ + assert(info->si_code =3D=3D SEGV_MTESERR); + exit(0); +} + +int main(int ac, char **av) +{ + struct sigaction sa; + int *p0, *p1, *p2; + long excl =3D 1; + + enable_mte(PR_MTE_TCF_SYNC); + p0 =3D alloc_mte_page(); + + /* Create two differently tagged pointers. */ + asm("irg %0,%1,%2" : "=3Dr"(p1) : "r"(p0), "r"(excl)); + asm("gmi %0,%1,%0" : "+r"(excl) : "r" (p1)); + assert(excl !=3D 1); + asm("irg %0,%1,%2" : "=3Dr"(p2) : "r"(p0), "r"(excl)); + assert(p1 !=3D p2); + + /* Store the tag from the first pointer. */ + asm("stg %0, [%0]" : : "r"(p1)); + + *p1 =3D 0; + + memset(&sa, 0, sizeof(sa)); + sa.sa_sigaction =3D pass; + sa.sa_flags =3D SA_SIGINFO; + sigaction(SIGSEGV, &sa, NULL); + + *p2 =3D 0; + + abort(); +} diff --git a/tests/tcg/aarch64/mte-3.c b/tests/tcg/aarch64/mte-3.c new file mode 100644 index 0000000000..6f034cdb01 --- /dev/null +++ b/tests/tcg/aarch64/mte-3.c @@ -0,0 +1,47 @@ +/* + * Memory tagging, basic fail cases. + */ + +#include "mte.h" + +void pass(int sig, siginfo_t *info, void *uc) +{ + assert(info->si_code =3D=3D SEGV_MTEAERR); + exit(0); +} + +int main(int ac, char **av) +{ + struct sigaction sa; + int *p0, *p1, *p2; + long excl =3D 1; + + enable_mte(PR_MTE_TCF_ASYNC); + p0 =3D alloc_mte_page(); + + /* Create two differently tagged pointers. */ + asm("irg %0,%1,%2" : "=3Dr"(p1) : "r"(p0), "r"(excl)); + asm("gmi %0,%1,%0" : "+r"(excl) : "r" (p1)); + assert(excl !=3D 1); + asm("irg %0,%1,%2" : "=3Dr"(p2) : "r"(p0), "r"(excl)); + assert(p1 !=3D p2); + + /* Store the tag from the first pointer. */ + asm("stg %0, [%0]" : : "r"(p1)); + + *p1 =3D 0; + + memset(&sa, 0, sizeof(sa)); + sa.sa_sigaction =3D pass; + sa.sa_flags =3D SA_SIGINFO; + sigaction(SIGSEGV, &sa, NULL); + + /* + * Signal for async error will happen eventually. + * For a real kernel this should be after the next IRQ (e.g. timer). + * For qemu linux-user, we kick the cpu and exit at the next TB. + * In either case, loop until this happens (or killed by timeout). + */ + *p2 =3D 0; + while (1); +} diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile= .target index cf84787eb6..2269c264df 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -31,6 +31,10 @@ bti-%: CFLAGS +=3D -mbranch-protection=3Dstandard bti-%: LDFLAGS +=3D -nostdlib endif =20 +# MTE Tests +AARCH64_TESTS +=3D mte-1 mte-2 mte-3 +mte-%: CFLAGS +=3D -march=3Darmv8.5-a+memtag + # Semihosting smoke test for linux-user AARCH64_TESTS +=3D semihosting run-semihosting: semihosting --=20 2.25.1