From nobody Tue May 21 01:32:47 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=1590574022; cv=none; d=zohomail.com; s=zohoarc; b=a4hjcFJ0f11kIBYCrTgmEjipJHegEuiUv3aZoFPHzxKYnGKli9mRAvhqOnGht0BCGGVnYHREFi2gyDrkX3qxA/1iuWYugIyBrBcIMg7y8Jx8ZE5BCzkOB/oZIvtYtn+iQ73myWd6IzptE99auInqr+XqmZqgdaqETkALyhjZfvA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590574022; h=Content-Type: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=Q9g2hw1e4m0meDSSDGhsHzYZBM3E+e3OyOVzFlX36Xg=; b=LD96tBaUZclXyaFJ8rfoCmlZYcuv4U7jK5KKeyYdj92FHVW5pBN6xFhO4lJAQtu5RD+0PvaNv85pxqqbJf0S/mMrwfyZLqUYSGAgHM4dPqsf13hPS7aVCgwcdXvi6V7dcmZp0bGtWB46lRJ5QPxHeNgprjflsa4w1m4CXUTf2K4= 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 1590574022993736.2435728854967; Wed, 27 May 2020 03:07:02 -0700 (PDT) Received: from localhost ([::1]:51696 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jdsxh-0004gb-PL for importer@patchew.org; Wed, 27 May 2020 06:07:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdswa-0003PH-Px for qemu-devel@nongnu.org; Wed, 27 May 2020 06:05:52 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:40712) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jdswZ-0005C0-Pe for qemu-devel@nongnu.org; Wed, 27 May 2020 06:05:52 -0400 Received: by mail-wr1-x443.google.com with SMTP id j16so10962323wrb.7 for ; Wed, 27 May 2020 03:05:51 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id m129sm1971380wmf.2.2020.05.27.03.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2020 03:05:47 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id DADDD1FF87; Wed, 27 May 2020 11:05:46 +0100 (BST) 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=Q9g2hw1e4m0meDSSDGhsHzYZBM3E+e3OyOVzFlX36Xg=; b=L8cIFL3jvF31gFLNhZfKcVyUva/SJZkPMo8p6jMPrz9TKGGYK7oi99G/yVQs0l5rxB s2hyzXGbYuN9G3dGjjZ3siAMbUhWWeYgy0sa/IdrzBtzbtYu7DVCx8anPINCqdw6OqBX fQX0N2c90JujLRS0y7xAjIMNn1n7QzS2FmvcaZMbhjrHVWjCiU2bL2n7HJnMpyXvfJVu 6DQEJPA5oIU47rDGAwKPrywGhIL/wENg0u5SxES7ngwlayE3/OhW7e3M5uFI9htloRLg HtZv/DGwcnDddISMtMWQPJuM2FgTMWtxT1HgWSPlNty9edvvsW1yTw8xGxOOHgnqzKOi HEtw== 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=Q9g2hw1e4m0meDSSDGhsHzYZBM3E+e3OyOVzFlX36Xg=; b=J8M9ARb4IZbfnBAFjglodGoXAaT+0zuLB4nZkvpvGHlvG4C7mdFl1Qc9JSw594aLZN WIM3ikA4JvPufu5tOK3XDSb7oyM91FAa9BAR1rNTL1Lc2/0ioNgGJDS4K8pGfHiJXSRq 3TYQ6z/DrdlXfcYaa7uLoTMeF/ABR7lWu3A5/xYN3Y+KYJp5MqKItY53v4BfyQmDGBJ8 Mi9m8HMB+0h/5dDCaCSMkrHv0ejT4v8Zdzclnsem+fDMDHbe+h7E9XwDP/LSLFoIo2wZ zAaQbEDWoqBqraF8tKLH4P/IyTiELkECkBVRLWlPDVsQwDk24BC4nN0rsD3mUXsw1vZr iDmQ== X-Gm-Message-State: AOAM530xbcQxPNZmNrlTA+UUhTKWeyaKhlQZLM++BP8sXnBeWCv5L/Qy 1rof5x/cCbYwdQ7T6j8KjtjZZA== X-Google-Smtp-Source: ABdhPJxFnYjDDBleWEc7OsrvheRhrr6oQPMLDU6sZQvh97QfYTG5+3VbQ5cECXIUB9twsyOk76ZlQg== X-Received: by 2002:adf:aa97:: with SMTP id h23mr21461385wrc.251.1590573950239; Wed, 27 May 2020 03:05:50 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 1/3] linux-user: provide fallback pgd_find_hole for bare chroots Date: Wed, 27 May 2020 11:05:44 +0100 Message-Id: <20200527100546.29297-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200527100546.29297-1-alex.bennee@linaro.org> References: <20200527100546.29297-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::443; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-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 , Riku Voipio , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) When running QEMU out of a chroot environment we may not have access to /proc/self/maps. As there is no other "official" way to introspect our memory map we need to fall back to the original technique of repeatedly trying to mmap an address range until we find one that works. Fortunately it's not quite as ugly as the original code given we already re-factored the complications of dealing with the ARM_COMMPAGE. We do make an attempt to skip over brk() which is about the only concrete piece of information we have about the address map at this moment. Fixes: ee9474303 Reported-by: Peter Maydell Signed-off-by: Alex Benn=C3=A9e --- linux-user/elfload.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 01a9323a637..d6027867a1a 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2099,6 +2099,50 @@ static void pgb_have_guest_base(const char *image_na= me, abi_ulong guest_loaddr, } } =20 +/** + * pgd_find_hole_fallback: potential mmap address + * @guest_size: size of available space + * @brk: location of break + * @align: memory alignment + * + * This is a fallback method for finding a hole in the host address + * space if we don't have the benefit of being able to access + * /proc/self/map. It can potentially take a very long time as we can + * only dumbly iterate up the host address space seeing if the + * allocation would work. + */ +static uintptr_t pgd_find_hole_fallback(uintptr_t guest_size, uintptr_t br= k, long align) +{ + uintptr_t base; + + /* Start at the bottom and work our way up */ + base =3D mmap_min_addr; + + while (true) { + uintptr_t align_start, end; + align_start =3D ROUND_UP(base, align); + end =3D align_start + guest_size; + + /* if brk is anywhere in the range give ourselves some room to gro= w. */ + if (align_start <=3D brk && brk < end) { + base +=3D 16 * MiB; + continue; + } else if (align_start + guest_size < align_start) { + /* we have run out of space */ + return -1; + } else { + int flags =3D MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE | MA= P_FIXED; + void * mmap_start =3D mmap((void *) align_start, guest_size, + PROT_NONE, flags, -1, 0); + if (mmap_start !=3D MAP_FAILED) { + munmap((void *) align_start, guest_size); + return (uintptr_t) mmap_start; + } + base +=3D qemu_host_page_size; + } + } +} + /* Return value for guest_base, or -1 if no hole found. */ static uintptr_t pgb_find_hole(uintptr_t guest_loaddr, uintptr_t guest_siz= e, long align) @@ -2114,6 +2158,10 @@ static uintptr_t pgb_find_hole(uintptr_t guest_loadd= r, uintptr_t guest_size, /* Read brk after we've read the maps, which will malloc. */ brk =3D (uintptr_t)sbrk(0); =20 + if (!maps) { + return pgd_find_hole_fallback(guest_size, brk, align); + } + /* The first hole is before the first map entry. */ this_start =3D mmap_min_addr; =20 --=20 2.20.1 From nobody Tue May 21 01:32:47 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=1590574040; cv=none; d=zohomail.com; s=zohoarc; b=hlb001H7oux7X9L3xJubLk6q1K3GY252u+d7ybNujNUagGszYFcBlbMaCfOMI3CZysMdAe9QnraHplKRsS9OTBJg36P4GXTKOLgg1ppWrNOpaHZ+Nw9bvFHEahrf0GFAI9jbBdmK/07X32TYQfsvYlqjorognKBjJorWq5Wdvgs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590574040; h=Content-Type: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=b1rnVPfR5Tx3kSg0YJymoHV+oJytl6k3F5aYs9rOE0Y=; b=ZpDVDxmYZlEkIwwZgTldOXtmmrce8rg8eaLdoNOSMr6lvyaSFfY8E9uO9QKExkz1IWtpGf80z2IcUrSXUGuZ0vqALwXs2qDcgiWvQE8m28zHvUNWUSjnRQw3Ysr0aVX0jD6yD4HzZCXIEq0NHuxdrbjvbNgY4DWdDgg198C58As= 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 1590574040410579.4105397493986; Wed, 27 May 2020 03:07:20 -0700 (PDT) Received: from localhost ([::1]:53326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jdsxz-0005XY-7U for importer@patchew.org; Wed, 27 May 2020 06:07:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdswd-0003UI-V3 for qemu-devel@nongnu.org; Wed, 27 May 2020 06:05:55 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:40713) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jdswc-0005D2-F8 for qemu-devel@nongnu.org; Wed, 27 May 2020 06:05:55 -0400 Received: by mail-wr1-x443.google.com with SMTP id j16so10962462wrb.7 for ; Wed, 27 May 2020 03:05:54 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id t6sm2202626wma.4.2020.05.27.03.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2020 03:05:50 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 128271FF8C; Wed, 27 May 2020 11:05:47 +0100 (BST) 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=b1rnVPfR5Tx3kSg0YJymoHV+oJytl6k3F5aYs9rOE0Y=; b=HSvZhak5TuyQi5IWGcjjOMlGbsZjF0Y+Pnnp7jg47KH8u9bziJp1RV+tyAD8bqemmj sc/d231xp3cX+xmGHphArsopMn6lH4g2eue939MRJSO1nEtp6Jj3Tk3yPfrwMK56wjfo SFiRSetkMr+HF+8kY22xMxhxb0X6xfXRQPxEQ2ylQ7GYpvdWMhKA0qcdjWSA/bVumNaK NEdKLeLeXzvfLE3oBy7g5IRI3lYpBGvjdfhDcdfQzVt0Od5/5KikGl0x2tUv/SrHCz0A 5NkszQYUfLpf36LG+LhnfKdleLh4PIGeovJAB/N5J3ouDj3YeUsiA6H2/s5xdju4BbPR Ux1Q== 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=b1rnVPfR5Tx3kSg0YJymoHV+oJytl6k3F5aYs9rOE0Y=; b=luCWEfqqms3TYeP7ofYO8ivXWwXIh7ajuvf8gOsQB7LYMzhMWslKF9LlcFLWmXZSRn imf+39Tq2L8bGNcXRFTR/iiEY1qLhVzIxxet9AtJ8X6ILP5evIR50AZ1yy+a5oDrwUs9 6Kq1FOp4LqV6IfjmfcOuFbpSLA6L6Hye/hAsmjLoEf+a5Q9MtCJNck38aRsq8KuQrAGc wj3aGBI2DtS17sjTg7AoslyW4r45om6yl0DH9FZE9rQpFJ6yWNnqEo2RhZpnrTTG4e1q u+EH7/eOheboVEaqO+f6Tcy/BY62A2lpPxvmAC9zBUkHUbboQHMa22VkFDE8bmzcqY0I q7/g== X-Gm-Message-State: AOAM530r04wcHUbiRyEryaRxsxNNJTvFtB8xHIGuO9a2efu+Ik8FyTXt 22uEf3iCj9tGW/6blS9fPCgm7w== X-Google-Smtp-Source: ABdhPJwQQYQvJ8dfw9OoTs7N7MoL/SPkhPy4dg/zXOcDNb6JejgS9x0+uuk0P+hSUaxQSDnKs9pCEA== X-Received: by 2002:adf:814a:: with SMTP id 68mr24367324wrm.177.1590573952701; Wed, 27 May 2020 03:05:52 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 2/3] linux-user: deal with address wrap for ARM_COMMPAGE on 32 bit Date: Wed, 27 May 2020 11:05:45 +0100 Message-Id: <20200527100546.29297-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200527100546.29297-1-alex.bennee@linaro.org> References: <20200527100546.29297-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::443; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-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 , Bug 1880225 <1880225@bugs.launchpad.net>, Riku Voipio , Richard Henderson , Laurent Vivier , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We rely on the pointer to wrap when accessing the high address of the COMMPAGE so it lands somewhere reasonable. However on 32 bit hosts we cannot afford just to map the entire 4gb address range. The old mmap trial and error code handled this by just checking we could map both the guest_base and the computed COMMPAGE address. We can't just manipulate loadaddr to get what we want so we introduce an offset which pgb_find_hole can apply when looking for a gap for guest_base that ensures there is space left to map the COMMPAGE afterwards. This is arguably a little inefficient for the one 32 bit value (kuser_helper_version) we need to keep there given all the actual code entries are picked up during the translation phase. Fixes: ee94743034b Bug: https://bugs.launchpad.net/qemu/+bug/1880225 Cc: Bug 1880225 <1880225@bugs.launchpad.net> Signed-off-by: Alex Benn=C3=A9e Cc: Richard Henderson Cc: Peter Maydell Tested-by: Aleksandar Markovic --- linux-user/elfload.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index d6027867a1a..31defce95b5 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2145,7 +2145,7 @@ static uintptr_t pgd_find_hole_fallback(uintptr_t gue= st_size, uintptr_t brk, lon =20 /* Return value for guest_base, or -1 if no hole found. */ static uintptr_t pgb_find_hole(uintptr_t guest_loaddr, uintptr_t guest_siz= e, - long align) + long align, uintptr_t offset) { GSList *maps, *iter; uintptr_t this_start, this_end, next_start, brk; @@ -2171,7 +2171,7 @@ static uintptr_t pgb_find_hole(uintptr_t guest_loaddr= , uintptr_t guest_size, =20 this_end =3D ((MapInfo *)iter->data)->start; next_start =3D ((MapInfo *)iter->data)->end; - align_start =3D ROUND_UP(this_start, align); + align_start =3D ROUND_UP(this_start + offset, align); =20 /* Skip holes that are too small. */ if (align_start >=3D this_end) { @@ -2221,6 +2221,7 @@ static void pgb_static(const char *image_name, abi_ul= ong orig_loaddr, { uintptr_t loaddr =3D orig_loaddr; uintptr_t hiaddr =3D orig_hiaddr; + uintptr_t offset =3D 0; uintptr_t addr; =20 if (hiaddr !=3D orig_hiaddr) { @@ -2234,18 +2235,19 @@ static void pgb_static(const char *image_name, abi_= ulong orig_loaddr, if (ARM_COMMPAGE) { /* * Extend the allocation to include the commpage. - * For a 64-bit host, this is just 4GiB; for a 32-bit host, - * the address arithmetic will wrap around, but the difference - * will produce the correct allocation size. + * For a 64-bit host, this is just 4GiB; for a 32-bit host we + * need to ensure there is space bellow the guest_base so we + * can map the commpage in the place needed when the address + * arithmetic wraps around. */ if (sizeof(uintptr_t) =3D=3D 8 || loaddr >=3D 0x80000000u) { hiaddr =3D (uintptr_t)4 << 30; } else { - loaddr =3D ARM_COMMPAGE & -align; + offset =3D (128 * KiB); } } =20 - addr =3D pgb_find_hole(loaddr, hiaddr - loaddr, align); + addr =3D pgb_find_hole(loaddr, hiaddr - loaddr, align, offset); if (addr =3D=3D -1) { /* * If ARM_COMMPAGE, there *might* be a non-consecutive allocation @@ -2280,7 +2282,7 @@ static void pgb_dynamic(const char *image_name, long = align) * just above that, and maximises the positive guest addresses. */ commpage =3D ARM_COMMPAGE & -align; - addr =3D pgb_find_hole(commpage, -commpage, align); + addr =3D pgb_find_hole(commpage, -commpage, align, 0); assert(addr !=3D -1); guest_base =3D addr; } --=20 2.20.1 From nobody Tue May 21 01:32:47 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=1590574085; cv=none; d=zohomail.com; s=zohoarc; b=gofEaDU4M1aJRa/qAMJRUwOEzmHQ3d3ZZdEotzPl6Y5uibefjWsIXK/Qxf9EdX6NLLFpKnJJqZMr7QuW02NLVFOrdnWXMePwjNZLSHYfYlqN+7XwnNCduZgqaqjgyUWibEA0aM2lRezh+/bh/gEYmJxacrSLEPP6n5+HbGD7CvM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590574085; h=Content-Type: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=7BwVQR+RWIzqLy1PIq/KCliSSJ727LeNTpr8QNS3EBg=; b=NTIXwqayvc7beU08sPIhrjBj8enUbGjkbeTwxJjz9dRzBRYdsV3B8JRhdVb2+BhATJKq1+SuUNSL6hlPY8aIzNFWIj/dYl6+Clhbw3KmkuDT+6xca7mitf2/ra39Bz+aVMHcplSJRdRSMwLJzMqIW8pbkiuxGPQrvUqxPq3JR+s= 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 1590574085333746.1706294288625; Wed, 27 May 2020 03:08:05 -0700 (PDT) Received: from localhost ([::1]:57090 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jdsyi-0007ZE-0q for importer@patchew.org; Wed, 27 May 2020 06:08:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50278) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdswd-0003UU-UM for qemu-devel@nongnu.org; Wed, 27 May 2020 06:05:55 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:41529) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jdswb-0005CZ-Cm for qemu-devel@nongnu.org; Wed, 27 May 2020 06:05:55 -0400 Received: by mail-wr1-x441.google.com with SMTP id j10so7799058wrw.8 for ; Wed, 27 May 2020 03:05:52 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id t6sm2202636wma.4.2020.05.27.03.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2020 03:05:50 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 479B81FF8F; Wed, 27 May 2020 11:05:47 +0100 (BST) 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=7BwVQR+RWIzqLy1PIq/KCliSSJ727LeNTpr8QNS3EBg=; b=OijwdnFog7MJOKgQXuIpzoT9zTo2dRa22snN1e8PLCTgtegtiufaLSHXf31GGRSzo5 i3EmIUqduEqP3s20UJIESHxq2Sy0zkU5gqtWbjJKOz6lqcH9VpTyX3iX4Zz+V++zEPbM nrWxXM6MVBIh9YyzSp12zYwLWdsWad/KhJAJMi29K+8Snk0AvjBPmvUVj3RPyduqeOGf yRRu5ZGGq/gO2hXnEAA2Vdp1PPdaAe0185NhbFZcH4TUfPbw3vSLf9CE7TqoWY2uGtPm Rt3OLk9viPuNE04H6uqTp/Y6NhiNGKB113jJejopfwxKOK0T1lrxS2uiwGQoHxT7VqfR Na7A== 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=7BwVQR+RWIzqLy1PIq/KCliSSJ727LeNTpr8QNS3EBg=; b=n9xBy2tdz3ssqYvdt7QBaMWtkRIsA4Ca69bo3zKtfEnqHlP3mJiKhjHxN7QZCS77/k oTaIRBVBbvyfNrg/sm2r8izx6TK9CDI9VQOCpCbppiQgaWW9y7vV9cz8FAifzPn0YCWV LSNHCXvvzkrHQg+aEbh0He6rZSqQ86HZZetvldJ2DG86aMhuiFJypk3PqCjHRnJGBKbK Ry/HPbZo9kyzCewBRFiXufnfob5NJCM+AR39jdlG1II4b6qco6W/mBDa7g+qiXMTwk5h pSmCG+14EGiLZcrk5z6nr9RAliQ+N7dnAoiGK1ZzhwpdBsGMIJBeeYA5wWpFY4vOuSGz 4qcQ== X-Gm-Message-State: AOAM5321Mra5RPHiL7jIovFA6i2Z4Q9PPuvO+rSSyMvVppbgOQAbadwZ 252NTATJR2c4YNk3Ax48D+akdg== X-Google-Smtp-Source: ABdhPJwGurJiv8ZSbyhr+zuL3upZs0F7DKctk9YFB3PPnoOrai7qTWgzQhABnoC9ExuVssKBuB4Lsw== X-Received: by 2002:adf:e38e:: with SMTP id e14mr25153823wrm.2.1590573951548; Wed, 27 May 2020 03:05:51 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 3/3] tests/tcg: add simple commpage test case Date: Wed, 27 May 2020 11:05:46 +0100 Message-Id: <20200527100546.29297-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200527100546.29297-1-alex.bennee@linaro.org> References: <20200527100546.29297-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::441; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -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 , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The COMMPAGE are a number of kernel provided user-space routines for 32 bit ARM systems. Add a basic series of smoke tests to ensure it is working as it should. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- tests/tcg/arm/commpage.c | 61 +++++++++++++++++++++++++++++++++++ tests/tcg/arm/Makefile.target | 2 ++ 2 files changed, 63 insertions(+) create mode 100644 tests/tcg/arm/commpage.c diff --git a/tests/tcg/arm/commpage.c b/tests/tcg/arm/commpage.c new file mode 100644 index 00000000000..c76e70cb8bd --- /dev/null +++ b/tests/tcg/arm/commpage.c @@ -0,0 +1,61 @@ +/* + * Verify the COMMPAGE emulation + * + * The ARM commpage is a set of user space helper functions provided + * by the kernel in an effort to ease portability of user space code + * between different CPUs with potentially different capabilities. It + * is a 32 bit invention and similar to the vdso segment in many ways. + * + * The ABI is documented in the Linux kernel: + * Documentation/arm/kernel_userspace_helpers.rst + * + * Copyright (c) 2020 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include + +#define ARM_COMMPAGE (0xffff0f00u) +#define ARM_KUSER_VERSION (*(int32_t *)(ARM_COMMPAGE + 0xfc)) +typedef void * (get_tls_fn)(void); +#define ARM_KUSER_GET_TLS (*(get_tls_fn *)(ARM_COMMPAGE + 0xe0)) +typedef int (cmpxchg_fn)(int oldval, int newval, volatile int *ptr); +#define ARM_KUSER_CMPXCHG (*(cmpxchg_fn *)(ARM_COMMPAGE + 0xc0)) +typedef void (dmb_fn)(void); +#define ARM_KUSER_DMB (*(dmb_fn *)(ARM_COMMPAGE + 0xa0)) +typedef int (cmpxchg64_fn)(const int64_t *oldval, + const int64_t *newval, + volatile int64_t *ptr); +#define ARM_KUSER_CMPXCHG64 (*(cmpxchg64_fn *)(ARM_COMMPAGE + 0x60)) + +#define fail_unless(x) \ + do { \ + if (!(x)) { \ + fprintf(stderr, "FAILED at %s:%d\n", __FILE__, __LINE__); \ + exit(EXIT_FAILURE); \ + } \ + } while (0) + + +int main(int argc, char *argv[argc]) +{ + void *kuser_tls; + int val =3D 1; + const int64_t oldval =3D 1, newval =3D 2; + int64_t val64 =3D 1; + + fail_unless(ARM_KUSER_VERSION =3D=3D 0x5); + kuser_tls =3D ARM_KUSER_GET_TLS(); + printf("TLS =3D %p\n", kuser_tls); + fail_unless(kuser_tls !=3D 0); + fail_unless(ARM_KUSER_CMPXCHG(1, 2, &val) =3D=3D 0); + printf("val =3D %d\n", val); + /* this is a crash test, not checking an actual barrier occurs */ + ARM_KUSER_DMB(); + fail_unless(ARM_KUSER_CMPXCHG64(&oldval, &newval, &val64) =3D=3D 0); + printf("val64 =3D %lld\n", val64); + return 0; +} diff --git a/tests/tcg/arm/Makefile.target b/tests/tcg/arm/Makefile.target index 11c39c601ea..3da09a38be7 100644 --- a/tests/tcg/arm/Makefile.target +++ b/tests/tcg/arm/Makefile.target @@ -68,6 +68,8 @@ run-semiconsole-arm: semiconsole-arm run-plugin-semiconsole-arm-with-%: $(call skip-test, $<, "MANUAL ONLY") =20 +ARM_TESTS +=3D commpage + TESTS +=3D $(ARM_TESTS) =20 # On ARM Linux only supports 4k pages --=20 2.20.1