From nobody Mon Apr 29 08:55:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.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=1571159111; cv=none; d=zoho.com; s=zohoarc; b=S1tx0zNcQ84FsM4wEN60h/NkI2UmpZeeby6UyRalELYVruacGiU6AFgzGUqKvYLGZrB27XzjjVRy+n2KXXKj7IAFSIpVcwN2Qq4dWbIfgkC6vnMzmgM5/1dyM1ftXvkovoSwXIUzQG/PEX1mdD91bFG1/tYhICnY7HKgQCVKLwg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571159111; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=nG2MQUfKXLXTBAN0GTjwypjxy4v62hiX+t+7N4V/tlY=; b=DwS5xHJg8CicyhhT2rAnIIVW4jyOEGL9BhgEDl8BJoxAVmKh7+6ufibl/01CKz0JqObS8quyiGY+ZWAmk0dLnsmkZvb6qvB6HibgP01qqs0GQ9uHCqAJWfbRNGylnWEz6pHcX6V/FhjIm5dYhZYd/iqFyH6CY85v9ubLWXwDksQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.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 1571159111120373.85254327124323; Tue, 15 Oct 2019 10:05:11 -0700 (PDT) Received: from localhost ([::1]:53510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKQFx-0005fi-UX for importer@patchew.org; Tue, 15 Oct 2019 13:05:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42526) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKPn0-0008D7-2p for qemu-devel@nongnu.org; Tue, 15 Oct 2019 12:35:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKPmy-0000FL-IW for qemu-devel@nongnu.org; Tue, 15 Oct 2019 12:35:13 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:43984) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iKPmy-0000En-D0 for qemu-devel@nongnu.org; Tue, 15 Oct 2019 12:35:12 -0400 Received: by mail-pg1-x541.google.com with SMTP id i32so12452809pgl.10 for ; Tue, 15 Oct 2019 09:35:12 -0700 (PDT) Received: from localhost.localdomain (97-113-7-119.tukw.qwest.net. [97.113.7.119]) by smtp.gmail.com with ESMTPSA id m22sm22011593pgj.29.2019.10.15.09.35.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 09:35:10 -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; bh=nG2MQUfKXLXTBAN0GTjwypjxy4v62hiX+t+7N4V/tlY=; b=MrbNyQOKu0lRjuiepV3ZsvSOZGjrtd509OrA78NZwrwagWfY44Q93qQx22mlumQChc ygPKc1ayqwLOJeb6j1N8MKiBPs6uyw6d2Gt7BgZddiGRv9NK0jZGut6x8qmKBj9GzOGd s1AyVKVKkq+OvpDGO2AcQEu0Y3djUISPshXeRv2CE2ECn2FMDZ4dR5fPLNx4JGKHylVI Mui1PANaVM112wNdj28XwE9oHVhbbTYv+9tNQRkm0IVdD8bNA7GhrdzHNF8euB7y7Sa6 w6qskEMoadlUN6PXLcYELh0Jm2ZRbnyA6QCEXUwhjCBz6ajpGuPxTTIAQF/zTxWawXsl yutg== 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; bh=nG2MQUfKXLXTBAN0GTjwypjxy4v62hiX+t+7N4V/tlY=; b=raizETIkRbmyzcS8nYg9/3iSd/tiWUW1bn2mUJvECN5C1w23oIJyLcuc8RfRD3OGn3 b8/CPo9LSuw30Qb92976uoNMrd20mLst2CdZgloQBfpwOmt64NH3ShOWyf0avasAKwmA nzzeSSz2UX0oo32btFIw/ABr1z7PWZNjyhgUJWuiVq2jcFXa7i5xqeol6ysjbaRO4m1a rEodTyfspmfg/78puJJLswhE0fXY48/UfyGOkX37r/ozse6XBYTHDfv2NorF4l5P/cTC olvkRF4ckWJXFMk+TEJP7gM1/cR7ljY10XWZscJJ7RdgGlvBNSfxP1JWaPd/OGHPA7pj 2R6Q== X-Gm-Message-State: APjAAAU8z1w8s+rVEHvjxBdztgxoMgZrXXt+dIpw0pJBLW0DtQ+AndRw l8SiTYpvGA7Pw0I9xc9Pf/djALnWnuE= X-Google-Smtp-Source: APXvYqzLlth/hZYOqANGKo7z1xa9prQJnxBb81m4tcTqlPl6wTTHcknhwUEi89cDnnbS3RlYiaYC5w== X-Received: by 2002:a65:5345:: with SMTP id w5mr31566979pgr.213.1571157310835; Tue, 15 Oct 2019 09:35:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 1/3] tcg: Introduce target-specific page data for user-only Date: Tue, 15 Oct 2019 09:35:05 -0700 Message-Id: <20191015163507.12153-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191015163507.12153-1-richard.henderson@linaro.org> References: <20191015163507.12153-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::541 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: elver@google.com, icb@rice.edu, qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" At the same time, remember MAP_SHARED as PAGE_SHARED. When mapping new pages, make sure that old target-specific page data is removed. Signed-off-by: Richard Henderson --- include/exec/cpu-all.h | 10 ++++++++-- accel/tcg/translate-all.c | 28 ++++++++++++++++++++++++++++ linux-user/mmap.c | 8 +++++++- linux-user/syscall.c | 4 ++-- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index d23ced1d12..034773e319 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -243,10 +243,14 @@ extern intptr_t qemu_host_page_mask; #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 +#define PAGE_WRITE_INV 0x0020 +/* Page is mapped shared. */ +#define PAGE_SHARED 0x0040 +/* For use with page_set_flags: page is being replaced; target_data cleare= d. */ +#define PAGE_RESET 0x0080 #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 @@ -261,6 +265,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 66d4bc4341..dbf08b55e2 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -110,6 +110,7 @@ typedef struct PageDesc { unsigned int code_write_count; #else unsigned long flags; + void *target_data; #endif #ifndef CONFIG_USER_ONLY QemuSpin lock; @@ -2513,6 +2514,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 @@ -2529,6 +2531,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; @@ -2542,10 +2546,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 c1bed290f6..75e0355ff7 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -626,6 +626,10 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, i= nt target_prot, } } the_end1: + if ((flags & MAP_TYPE) =3D=3D MAP_SHARED) { + page_flags |=3D PAGE_SHARED; + } + page_flags |=3D PAGE_RESET; page_set_flags(start, start + len, page_flags); the_end: #ifdef DEBUG_MMAP @@ -818,9 +822,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 e2af3c1494..52f50eca4b 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4061,8 +4061,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_SHARED | 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.17.1 From nobody Mon Apr 29 08:55:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.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=1571158804; cv=none; d=zoho.com; s=zohoarc; b=LdD3Bh8ei2GiJLIY4LfC1kpgzIiLV2Wkme3gE/7bbaKBuEouz8c0j6A3102qvvsVHSg+fZOTi54XaUIpbGpIMbUDFRhOmju0okYWC6BmyRhiuBjf/2uB9zWLR7c2DADE/scGjh0IQHVKWpMKrmGu9QhBGO5wRsnTaNVySm0XZlY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571158804; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Z9j8volhtgefXr986PnBR9GXQR8t6Mv7RUHoAURHFm8=; b=VUj4MNNF4h8BPKvlMxRJJF2n6MWbuE/liCMUf41mMQHgnRNJIOd0UTy8qaHcoBACiNCuSxokafcjf3MbdGGo0Sz3LBXnsoE+hbSzwM5H4z7ZL9+qgjhFhxb5zMxhtd52f2H3s47biuvRQu5FQOdIsLBuYfzoVAZgSYCwlE4H38k= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.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 1571158804903794.4547151633715; Tue, 15 Oct 2019 10:00:04 -0700 (PDT) Received: from localhost ([::1]:53242 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKQAy-0007i6-Hi for importer@patchew.org; Tue, 15 Oct 2019 13:00:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42553) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKPn1-0008FH-AE for qemu-devel@nongnu.org; Tue, 15 Oct 2019 12:35:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKPmz-0000Ga-Rm for qemu-devel@nongnu.org; Tue, 15 Oct 2019 12:35:15 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:40797) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iKPmz-0000Fo-MY for qemu-devel@nongnu.org; Tue, 15 Oct 2019 12:35:13 -0400 Received: by mail-pf1-x441.google.com with SMTP id x127so12816432pfb.7 for ; Tue, 15 Oct 2019 09:35:13 -0700 (PDT) Received: from localhost.localdomain (97-113-7-119.tukw.qwest.net. [97.113.7.119]) by smtp.gmail.com with ESMTPSA id m22sm22011593pgj.29.2019.10.15.09.35.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 09:35:11 -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; bh=Z9j8volhtgefXr986PnBR9GXQR8t6Mv7RUHoAURHFm8=; b=nj1pctCulV9XzosVS4Royndi5VtaskoPn9t4VdjMis/CyzTEtURqNjpJZd22x7ZYpm WLYNEe5spgDEGTfxWf1gDIRqnF1u5qw1KKb/W+T/j4YS4cNnWOpedfXn7cpzKSfcFPNN +Sjb/QdFyozo32/PHJDjJxA11DRbV4JT+sFVoC+UlK4HoYmleHgjnAdkNIDLl8zsUcfQ h0vW2R4JMp0yh4djyTz+GSF/Z4kbwzriTJC9n+umFLa+tM6aH00aqsEV862DdVGhiC6J jaXWBawM0qW8E2GzGn/kbCxsLaRA81/AKT4LD6+XEP4mrgesvzFbkMkkgGmAZAoCgW5B qLJA== 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; bh=Z9j8volhtgefXr986PnBR9GXQR8t6Mv7RUHoAURHFm8=; b=iPOe91QAX2iqBX1lrw+mO3CkCjj0SWtsqFlGGKCa+MdtO1wpMJ6G5kT2iwRJG1MDNN mcTIoSvpONYLrJzUJBtycjAw3uo2Wu7aUEiWpLHM74lXoI3lxIKVxHz0d9Lw9y54ApAI IKI5g4P3hlPMQ8nNmRu/F4MvarFd3fHsVCnWGsGKKWHSP9jSkRaV41AkUaqUjQ5/9eaQ K2boR3UVf6+b6oLorzsMsZ141lVJ44sS/ekFH0cPH24mTi4JAzPr08VmIlMFpkAgU/XT 0qWCmP3TUoND/9iSiWtJPTkLSzVoPgGy7MTpjP23bFYa/qAdNtawZIWw8uxxyLod4R5h d1EQ== X-Gm-Message-State: APjAAAUxVhGs4V5AdiYd1vvFCtkKBQHhRHKzENo3aYb/kbzQ5ImjYnco 32YLDNYWoTzyjr7/fQnNOMkjF4cZkDo= X-Google-Smtp-Source: APXvYqxkIeYn7eLe7ZWHcykV6S2alU5GzCLCwJhFOCLrbLgmfwdUW5N8tLr/k8ha/G3FoS7quW8B9A== X-Received: by 2002:a17:90a:9b86:: with SMTP id g6mr43664202pjp.76.1571157312303; Tue, 15 Oct 2019 09:35:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 2/3] target/arm: Add allocation tag storage for user mode Date: Tue, 15 Oct 2019 09:35:06 -0700 Message-Id: <20191015163507.12153-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191015163507.12153-1-richard.henderson@linaro.org> References: <20191015163507.12153-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::441 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: elver@google.com, icb@rice.edu, qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Control this with x-tagged-pages, which is off by default. The limitation to non-shared pages is not part of a future kernel API, but a limitation of linux-user not being able to map virtual pages back to physical pages. Signed-off-by: Richard Henderson --- v2: Add the x-tagged-pages cpu property --- target/arm/cpu.h | 4 ++++ target/arm/cpu64.c | 20 ++++++++++++++++++++ target/arm/mte_helper.c | 35 +++++++++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index c3609ef9d5..272df43d3c 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -912,6 +912,10 @@ struct ARMCPU { */ bool cfgend; =20 +#ifdef CONFIG_USER_ONLY + bool tagged_pages; +#endif + QLIST_HEAD(, ARMELChangeHook) pre_el_change_hooks; QLIST_HEAD(, ARMELChangeHook) el_change_hooks; =20 diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index ac1e2dc2c4..4bf498f778 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -279,6 +279,20 @@ static void cpu_max_set_sve_vq(Object *obj, Visitor *v= , const char *name, error_propagate(errp, err); } =20 +#ifdef CONFIG_USER_ONLY +static bool aarch64_cpu_get_tagged_pages(Object *obj, Error **errp) +{ + ARMCPU *cpu =3D ARM_CPU(obj); + return cpu->tagged_pages; +} + +static void aarch64_cpu_set_tagged_pages(Object *obj, bool val, Error **er= rp) +{ + ARMCPU *cpu =3D ARM_CPU(obj); + cpu->tagged_pages =3D val; +} +#endif + /* -cpu max: if KVM is enabled, like -cpu host (best possible with this ho= st); * otherwise, a CPU with as many features enabled as our emulation support= s. * The version of '-cpu max' for qemu-system-arm is defined in cpu.c; @@ -389,6 +403,12 @@ static void aarch64_max_initfn(Object *obj) */ cpu->ctr =3D 0x80038003; /* 32 byte I and D cacheline size, VIPT i= cache */ cpu->dcz_blocksize =3D 7; /* 512 bytes */ + + object_property_add_bool(obj, "x-tagged-pages", + aarch64_cpu_get_tagged_pages, + aarch64_cpu_set_tagged_pages, NULL); + object_property_set_description(obj, "x-tagged-pages", + "Set on/off MemAttr Tagged for all pages", NULL); #endif =20 cpu->sve_max_vq =3D ARM_MAX_VQ; diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c index 657383ba0e..797c6229ab 100644 --- a/target/arm/mte_helper.c +++ b/target/arm/mte_helper.c @@ -29,8 +29,39 @@ static uint8_t *allocation_tag_mem(CPUARMState *env, uin= t64_t ptr, bool write, uintptr_t ra) { #ifdef CONFIG_USER_ONLY - /* Tag storage not implemented. */ - return NULL; + ARMCPU *cpu =3D env_archcpu(env); + uint8_t *tags; + uintptr_t index; + int flags; + + flags =3D page_get_flags(ptr); + + if (!(flags & PAGE_VALID) || !(flags & (write ? PAGE_WRITE : PAGE_READ= ))) { + /* SIGSEGV */ + env->exception.vaddress =3D ptr; + cpu_restore_state(CPU(cpu), ra, true); + raise_exception(env, EXCP_DATA_ABORT, 0, 1); + } + + if (!cpu->tagged_pages) { + /* Tag storage is disabled. */ + return NULL; + } + if (flags & PAGE_SHARED) { + /* There may be multiple mappings; pretend not implemented. */ + return NULL; + } + + tags =3D page_get_target_data(ptr); + if (tags =3D=3D NULL) { + size_t alloc_size =3D TARGET_PAGE_SIZE >> (LOG2_TAG_GRANULE + 1); + tags =3D page_alloc_target_data(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 CPUState *cs =3D env_cpu(env); uintptr_t index; --=20 2.17.1 From nobody Mon Apr 29 08:55:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.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=1571158658; cv=none; d=zoho.com; s=zohoarc; b=L+4rVqiMzIEU31n5DM3SxiSUaoLPg8sE0AGsoJXLQD2ZmzIEY3FSTBsOWNadae7ZSN/yNQ9rwrXMEvWuDmijMb5wAZSGDCYUheyGu5ogBBkPgPYK/4RsbgE/7uQW8II6JCIRuenQVZpt8Zx+xLtj1AQB/btuOZTXIX/qyVBmO9Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571158658; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=m4O3Xy7tWLBs5UuOTJ5dzdaA6h4n+q00OCHjnj+1vK8=; b=MCKi+dqX6ytQp+agPB7yrYw8clBYGUATzlnZPWdsSTzIXJiW8f0V7fweAU7UgTTcewvf07kcon80MMp6oHy1QMCw+gU7drMwizEVp7bmrOC7wU9gCb+nbCJtU1of7GJ+6rtV+xFz/vmuxE5e+xBAb882PmlVVC5jjP/ahDnHK9k= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.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 1571158658419685.4697924501492; Tue, 15 Oct 2019 09:57:38 -0700 (PDT) Received: from localhost ([::1]:53166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKQ8f-0003q9-9O for importer@patchew.org; Tue, 15 Oct 2019 12:57:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42579) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKPn2-0008HK-JJ for qemu-devel@nongnu.org; Tue, 15 Oct 2019 12:35:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKPn1-0000Ic-BP for qemu-devel@nongnu.org; Tue, 15 Oct 2019 12:35:16 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:38713) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iKPn1-0000HW-5v for qemu-devel@nongnu.org; Tue, 15 Oct 2019 12:35:15 -0400 Received: by mail-pf1-x442.google.com with SMTP id h195so12826990pfe.5 for ; Tue, 15 Oct 2019 09:35:15 -0700 (PDT) Received: from localhost.localdomain (97-113-7-119.tukw.qwest.net. [97.113.7.119]) by smtp.gmail.com with ESMTPSA id m22sm22011593pgj.29.2019.10.15.09.35.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 09:35:12 -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; bh=m4O3Xy7tWLBs5UuOTJ5dzdaA6h4n+q00OCHjnj+1vK8=; b=TE/G92PHYDbz91JtzP8GE/LU/s06l3o0trtKUl5FKEffqZNPOpEurSJ4FBzjfTISD2 /lVZYw4s7DqW8g51X+BQGYyef8qCiqeZQkP1oa2JYc4Z4RWEbVsh8IOILSWCt5WFAvRk 1wZWvB3gjOBEqH9+qVTuKKK8GsPbhtS2fXeXMmiaT37Y8x1mIi+NvekCyxln1O2opmLk HXhwRP/Aya9Zv2VSKw2UTYCrNZgGuw/9/+0AqTpgvGdYAWvEv50/iZ+g9yXhbxiYWWOP zmvDOpPmx9E/dJR+hDtYU50QacP12Vze4l+2axHMBELlJueUPJJzv0bY4qhvcOUWlElp ZZlw== 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; bh=m4O3Xy7tWLBs5UuOTJ5dzdaA6h4n+q00OCHjnj+1vK8=; b=nrV+rkcXJxmnFfclMBMoxED74+p/SlSEJ1h3qaA0cZpOxmUn1UMmQvAU9u4lrX3PCA ZRo9SrG8LAqW8vu6xkvGTHoF0GrlY99NjeTKuauyV27iJW2ml8eB7aM8afXsJ0I8jzRb yVCb/JTSDAtkhNDWGEOxQyVTpL0a2MEG1NjzIQenKuC9VSg/N8TljLlS2VTBFPahaFle pA65jjJPF18vLjavGomKVm/0xEswRTvXkwaz/DLclNQRh+djlCNZyJlJhgnA2Zb2QtHL npicUQhqh240MkU/YwAzYnILqB5mUqXcom9avna+MMGjISqhbU6YaskkID9X4k6G7nVA Gm7Q== X-Gm-Message-State: APjAAAUcy+jWNq1vF+TCm1qjMBc8FPzD4BBvWg1aB0P4AGNBdiYFdWu/ RQByQDTPSmWtMzfPLgw9KfnxX6AXYew= X-Google-Smtp-Source: APXvYqz2uCiuKMXXRRK9lIVML/Zp5UEtKKiq15BJ9llu13JVcpuKlEOIcCdAjTN2tlcOa6Kmea+0Ow== X-Received: by 2002:a17:90a:654b:: with SMTP id f11mr43562323pjs.49.1571157313791; Tue, 15 Oct 2019 09:35:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 3/3] tests/tcg/aarch64: Add mte smoke tests Date: Tue, 15 Oct 2019 09:35:07 -0700 Message-Id: <20191015163507.12153-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191015163507.12153-1-richard.henderson@linaro.org> References: <20191015163507.12153-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 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: elver@google.com, icb@rice.edu, qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- tests/tcg/aarch64/mte-1.c | 27 +++++++++++++++++++++ tests/tcg/aarch64/mte-2.c | 39 +++++++++++++++++++++++++++++++ tests/tcg/aarch64/Makefile.target | 5 ++++ 3 files changed, 71 insertions(+) create mode 100644 tests/tcg/aarch64/mte-1.c create mode 100644 tests/tcg/aarch64/mte-2.c diff --git a/tests/tcg/aarch64/mte-1.c b/tests/tcg/aarch64/mte-1.c new file mode 100644 index 0000000000..18bfb1120f --- /dev/null +++ b/tests/tcg/aarch64/mte-1.c @@ -0,0 +1,27 @@ +/* + * Memory tagging, basic pass cases. + */ + +#include + +asm(".arch armv8.5-a+memtag"); + +int data[16 / sizeof(int)] __attribute__((aligned(16))); + +int main(int ac, char **av) +{ + int *p0 =3D data; + int *p1, *p2; + long c; + + 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..2991b7df69 --- /dev/null +++ b/tests/tcg/aarch64/mte-2.c @@ -0,0 +1,39 @@ +/* + * Memory tagging, basic fail cases. + */ + +#include +#include +#include + +asm(".arch armv8.5-a+memtag"); + +int data[16 / sizeof(int)] __attribute__((aligned(16))); + +void pass(int sig) +{ + exit(0); +} + +int main(int ac, char **av) +{ + int *p0 =3D data; + int *p1, *p2; + long excl =3D 1; + + /* 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; + signal(SIGSEGV, pass); + *p2 =3D 0; + + assert(0); +} diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile= .target index 0040b68dd0..0971c244b7 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -32,4 +32,9 @@ run-semihosting: semihosting # AARCH64_TESTS +=3D bti-1 bti-1: LDFLAGS +=3D -nostdlib -Wl,-T,$(AARCH64_SRC)/bti.ld =20 +# We need binutils-2.32 to assemble this test case. +# AARCH64_TESTS +=3D mte-1 mte-2 +mte-%: CFLAGS +=3D -O -g +run-mte-%: QEMU +=3D -cpu max,x-tagged-pages=3Don + TESTS +=3D $(AARCH64_TESTS) --=20 2.17.1