Received: by 10.223.164.202 with SMTP id h10csp6060611wrb; Tue, 21 Nov 2017 21:42:34 -0800 (PST) X-Google-Smtp-Source: AGs4zMY3KwDZY12NTiOIB4HCvvII29YYoOWXSFzCqhAV2D8xnOPZ6PTdgS9p+95yDLJtIiA6Y/m8 X-Received: by 10.101.87.139 with SMTP id b11mr19884828pgr.314.1511329354652; Tue, 21 Nov 2017 21:42:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511329354; cv=none; d=google.com; s=arc-20160816; b=QPZTEa0Fcp4MIvSJx7T6NdbsFFMoqNA4L6mf6Vws8vBcz5uk6YVYcDG7+n+IIuwVwA JrrdD2f4bTig2jjqz4gqESg9XAMvcoDibnsbWnrKN5d1pZ2l8N8c5yWI9KnGhzJh4rNt bJcXbUICqJSBKivFVolJsskGNSc8RprY/XwGUoUxInt1MOPK7S7WiRLG/D20dz2cU5c9 TDevm5GmC95+OpRR3PVRh2m9T/U85gao6mGKUeGeAVTLG2cRRKFIbJ8gPd3PB8pzHtk/ +IVy+R/Hsr+jFqojxi9oSBsLRaCm0lo3TaDKkMhe2f/7VMCJSMNLmR1t9FecviyFRwnc Enlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:mime-version:date:references :in-reply-to:subject:cc:to:from:arc-authentication-results; bh=na3X+4CZUdVud7Ifqo2RKQg2XrpSHngDebj3DYLWaNk=; b=rVlaouMcqs4voLRh2znt4U3opiQWxy8rzt3YfOV+Us2VsNobjUsrkG5mv0MOtREVVH haOhOGiNqSgZaeIY4vM1Y/8+6gm43KRfsOs5vcAVGPjdg0F5EcABSczcbDV2SC0rVvWx HQizgMaiqs6ozZo3r0Vr4Bjibw+HTC4VNcW6I7y5eaIXebKat2JXN6tKM3HosnyzxQa+ R3E6E9cNoWiqxBsBYSTmLpfLr3gKVr4ZlH8bTtgU+hDKTjPlF2RSUOPKM+IIv0MQ0c9j aZuOpiPvp2fr3Pybt8SKcUe2r76wC6A9ScbkWLJfOc+joE/Nj0cTflIgP8x51SC8x1QG hEag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w9si4772052pgp.493.2017.11.21.21.42.23; Tue, 21 Nov 2017 21:42:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751470AbdKVFls (ORCPT + 76 others); Wed, 22 Nov 2017 00:41:48 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:36484 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751079AbdKVFlr (ORCPT ); Wed, 22 Nov 2017 00:41:47 -0500 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAM5dEi0107427 for ; Wed, 22 Nov 2017 00:41:46 -0500 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0b-001b2d01.pphosted.com with ESMTP id 2ed2hfhbfu-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 22 Nov 2017 00:41:46 -0500 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 Nov 2017 05:41:44 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 22 Nov 2017 05:41:40 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAM5fdfx7012556; Wed, 22 Nov 2017 05:41:39 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 46235A4057; Wed, 22 Nov 2017 05:36:20 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 53979A4055; Wed, 22 Nov 2017 05:36:18 +0000 (GMT) Received: from skywalker (unknown [9.124.35.86]) by d06av23.portsmouth.uk.ibm.com (Postfix) with SMTP; Wed, 22 Nov 2017 05:36:18 +0000 (GMT) Received: (nullmailer pid 1989 invoked by uid 1000); Wed, 22 Nov 2017 05:41:36 -0000 From: "Aneesh Kumar K.V" To: "Kirill A. Shutemov" , Ingo Molnar , x86@kernel.org, Thomas Gleixner , "H. Peter Anvin" Cc: Linus Torvalds , Andy Lutomirski , Nicholas Piggin , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: Re: [PATCHv3 2/2] x86/selftests: Add test for mapping placement for 5-level paging In-Reply-To: <20171115143607.81541-2-kirill.shutemov@linux.intel.com> References: <20171115143607.81541-1-kirill.shutemov@linux.intel.com> <20171115143607.81541-2-kirill.shutemov@linux.intel.com> Date: Wed, 22 Nov 2017 11:11:36 +0530 MIME-Version: 1.0 Content-Type: text/plain X-TM-AS-GCONF: 00 x-cbid: 17112205-0012-0000-0000-00000590335A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112205-0013-0000-0000-0000190B0593 Message-Id: <87y3myzx7z.fsf@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-22_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711220078 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "Kirill A. Shutemov" writes: > With 5-level paging, we have 56-bit virtual address space available for > userspace. But we don't want to expose userspace to addresses above > 47-bits, unless it asked specifically for it. > > We use mmap(2) hint address as a way for kernel to know if it's okay to > allocate virtual memory above 47-bit. > > Let's add a self-test that covers few corner cases of the interface. > > Signed-off-by: Kirill A. Shutemov Can we move this to selftest/vm/ ? I had a variant which i was using to test issues on ppc64. One change we did recently was to use >=128TB as the hint addr value to select larger address space. I also would like to check for exact mmap return addr in some case. Attaching below the test i was using. I will check whether this patch can be updated to test what is converted in my selftest. I also want to do the boundary check twice. The hash trasnslation mode in POWER require us to track addr limit and we had bugs around address space slection before and after updating the addr limit. >From 7739eb02bb6b6602572a9c259e915ef23950aae1 Mon Sep 17 00:00:00 2001 From: "Aneesh Kumar K.V" Date: Mon, 13 Nov 2017 10:41:10 +0530 Subject: [PATCH] selftest/mm: Add test for checking mmap across 128TB boundary Signed-off-by: Aneesh Kumar K.V --- tools/testing/selftests/vm/Makefile | 1 + tools/testing/selftests/vm/run_vmtests | 11 ++ tools/testing/selftests/vm/va_128TBswitch.c | 170 ++++++++++++++++++++++++++++ 3 files changed, 182 insertions(+) create mode 100644 tools/testing/selftests/vm/va_128TBswitch.c diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile index cbb29e41ef2b..b1fb3cd7cf52 100644 --- a/tools/testing/selftests/vm/Makefile +++ b/tools/testing/selftests/vm/Makefile @@ -17,6 +17,7 @@ TEST_GEN_FILES += transhuge-stress TEST_GEN_FILES += userfaultfd TEST_GEN_FILES += mlock-random-test TEST_GEN_FILES += virtual_address_range +TEST_GEN_FILES += va_128TBswitch TEST_PROGS := run_vmtests diff --git a/tools/testing/selftests/vm/run_vmtests b/tools/testing/selftests/vm/run_vmtests index 07548a1fa901..b367f7801b67 100755 --- a/tools/testing/selftests/vm/run_vmtests +++ b/tools/testing/selftests/vm/run_vmtests @@ -176,4 +176,15 @@ else echo "[PASS]" fi +echo "-----------------------------" +echo "running virtual address 128TB switch test" +echo "-----------------------------" +./va_128TBswitch +if [ $? -ne 0 ]; then + echo "[FAIL]" + exitcode=1 +else + echo "[PASS]" +fi + exit $exitcode diff --git a/tools/testing/selftests/vm/va_128TBswitch.c b/tools/testing/selftests/vm/va_128TBswitch.c new file mode 100644 index 000000000000..dfa501b825a8 --- /dev/null +++ b/tools/testing/selftests/vm/va_128TBswitch.c @@ -0,0 +1,170 @@ +/* + * Copyright IBM Corporation, 2017 + * Author Aneesh Kumar K.V + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + */ + +#include +#include +#include + +#ifdef DEBUG +#define pr_debug(fmt, ...) printf(fmt, ##__VA_ARGS__) +#else +#define pr_debug(fmt, ...) +#endif + +/* + * >= 128TB is the hint addr value we used to select + * large address space. + */ +#define ADDR_SWITCH_HINT (1UL << 47) + +#ifdef __powerpc64__ +#define MAP_SIZE 64*1024 +#else +#define MAP_SIZE 4*1024 +#endif + + +void report_failure(long in_addr, unsigned long flags) +{ + printf("Failed to map 0x%lx with flags 0x%lx\n", in_addr, flags); + exit(1); +} + +int *__map_addr(long in_addr, int size, unsigned long flags, int unmap) +{ + int *addr; + + addr = (int *)mmap((void *)in_addr, size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE | flags, -1, 0); + if (addr == MAP_FAILED) + report_failure(in_addr, flags); + pr_debug("Mapped addr 0x%lx-0x%lx for request 0x%lx with flag 0x%lx\n", + (unsigned long)addr, ((unsigned long)addr + size), in_addr, flags); + /* + * Try to access to catch errors in fault handling/slb miss handling + */ + *addr = 10; + if (unmap) + munmap(addr, size); + return addr; +} + +int *map_addr(long in_addr, unsigned long flags, int unmap) +{ + return __map_addr(in_addr, MAP_SIZE, flags, unmap); +} + +void boundary_check(void) +{ + int *a; + + /* + * If stack is moved, we could possibly allocate + * this at the requested address. + */ + a = map_addr((ADDR_SWITCH_HINT - MAP_SIZE), 0, 1); + if ((unsigned long)a > ADDR_SWITCH_HINT - MAP_SIZE) + report_failure(ADDR_SWITCH_HINT - MAP_SIZE, 0); + + /* + * We should never allocate at the requested address or above it + * The len cross the 128TB boundary. Without MAP_FIXED + * we will always search in the lower address space. + */ + a = __map_addr((ADDR_SWITCH_HINT - MAP_SIZE), 2*MAP_SIZE, 0, 1); + if ((unsigned long)a >= ADDR_SWITCH_HINT - MAP_SIZE) + report_failure(ADDR_SWITCH_HINT - MAP_SIZE, 0); + /* + * Exact mapping at 128TB, the area is free we should get that + * even without MAP_FIXED. Don't unmap. We check fixed in the + * same range later. + */ + a = map_addr(ADDR_SWITCH_HINT, 0, 0); + if ((unsigned long)a != ADDR_SWITCH_HINT) + report_failure(ADDR_SWITCH_HINT, 0); + + a = map_addr(ADDR_SWITCH_HINT + MAP_SIZE, 0, 1); + if ((unsigned long)a < ADDR_SWITCH_HINT) + report_failure(ADDR_SWITCH_HINT, 0); + +#if 0 + /* + * Enable this with stack mapped MAP_SIZE below 128TB + */ + a = map_addr((ADDR_SWITCH_HINT - MAP_SIZE), MAP_FIXED, 1); + if ((unsigned long)a != ADDR_SWITCH_HINT - MAP_SIZE) + report_failure(ADDR_SWITCH_HINT - MAP_SIZE, 0); + a = __map_addr((ADDR_SWITCH_HINT - MAP_SIZE), 2*MAP_SIZE, MAP_FIXED, 1); + if ((unsigned long)a != ADDR_SWITCH_HINT - MAP_SIZE) + report_failure(ADDR_SWITCH_HINT - MAP_SIZE, MAP_FIXED); + +#endif + a = map_addr(ADDR_SWITCH_HINT, MAP_FIXED, 1); + if ((unsigned long)a != ADDR_SWITCH_HINT) + report_failure(ADDR_SWITCH_HINT, MAP_FIXED); +} + +static int supported_arch(void) +{ +#if defined(__powerpc64__) + return 1; +#elif defined(__x86_64__) + return 1; +#else + return 0; +#endif + +} + +int main(int argc, char *argv[]) +{ + int *a; + + if (!supported_arch()) + return 0; + /* + * check the 128TB boundary before we update addr_limit + */ + boundary_check(); + + a = map_addr(0, 0, 1); + if ((unsigned long)a > ADDR_SWITCH_HINT) + report_failure(0, 0); + + a = map_addr(-1, 0, 1); + if ((unsigned long)a < ADDR_SWITCH_HINT) + report_failure(-1, 0); + + /* don't unmap this one */ + a = map_addr((1UL << 48), 0, 0); + if ((unsigned long)a != 1UL << 48) + report_failure((1UL << 48), 0); + + a = map_addr((1UL << 48), 0, 1); + if ((unsigned long)a < ADDR_SWITCH_HINT) + report_failure((1UL << 48), 0); + + a = map_addr(0, 0, 1); + if ((unsigned long)a > ADDR_SWITCH_HINT) + report_failure(0, 0); + + a = map_addr(-1, 0, 1); + if ((unsigned long)a < ADDR_SWITCH_HINT) + report_failure(-1, 0); + /* + * Try boundary conditions again after we allocated something above 128TB + * and updated addr_limit. + */ + boundary_check(); +} -- 2.14.3 From 1584240830716377008@xxx Thu Nov 16 16:29:51 +0000 2017 X-GM-THRID: 1584229946535540405 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread