Received: by 10.223.164.202 with SMTP id h10csp47081wrb; Wed, 22 Nov 2017 03:37:51 -0800 (PST) X-Google-Smtp-Source: AGs4zMaxIu65mO7oLXtjdt8YdZQuanCjxJBPMaeevRaaX8XuZl5SsFMvMsoeMnVwRtUMEu/shnpO X-Received: by 10.98.245.221 with SMTP id b90mr19014786pfm.203.1511350671720; Wed, 22 Nov 2017 03:37:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511350671; cv=none; d=google.com; s=arc-20160816; b=YUiOI+Sm+qnEnjdWa08oqTuUrwRyPJIH2L9al21A6MO+bHYYtQLtcyqMdCWJ0APCL2 IKd7NU8OYUzx3ChrMpDGPGZe3tl1qPODLLMHPT02rqSww5vzuG+SwVjj4NwsWZWjb1WE fdJhi6EKLzLxUur0gUUHCff2qR/xzjVpU1nhnxGzftm2cWbzhlgRou9GX0d3WnDeCK5H iumk/ZMYl+HQma8lsFj+vX7wzceWQkYgPDSf1OvUX6K8raF/2Q3mfFTiiN5lyk8ymzcB Wa94KD3MLwvgQn2uzGsbDYfYE2fTgAMUcCBE4/QKsslBV+XFaAfWYpfO3DMKaTOPGInu 83WA== 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=2PeaplMJQcrIrS4k28CPxAByKbyZ93roEF+7plCApQU=; b=uwo1JKFxpHxBih3fmO4/r0qoWUBKWUNcyj5/XX6Lc4tKR/rWhOgBwimXRvjyZM77wC FTkAWMa6zfR1d5TeXdIK8OhcZQKAOJ47I/ABqFqlC9Sfon6rDjin+jY1hnMJLOfZatwa o69/lOYqhd8fSyHWIVn7uKJK0SzuLKc2XYMKRR4bBzNV4FZoW4jd78mmh2+60h8jCF0M LsWt8G6cROFVsa6Vuv1NqXPF/LYzmE89Cf1MK4P75g7kOck5jnT14Z9hyivDvzXX11gI f7Hz6tNhWJD057jbFtE58vKq9UgxQB82n5Vo2Epdot60dG1+HEWIuvJyExEBYdRpO11g WOIw== 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 b3si13202710pgn.773.2017.11.22.03.37.40; Wed, 22 Nov 2017 03:37:51 -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 S1752229AbdKVLgj (ORCPT + 77 others); Wed, 22 Nov 2017 06:36:39 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:34346 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752158AbdKVLgh (ORCPT ); Wed, 22 Nov 2017 06:36:37 -0500 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAMBYIeT101580 for ; Wed, 22 Nov 2017 06:36:37 -0500 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ed8aprkt6-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 22 Nov 2017 06:36:36 -0500 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 Nov 2017 11:36:34 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 22 Nov 2017 11:36:30 -0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAMBaUSm23396432; Wed, 22 Nov 2017 11:36:30 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 09B6442049; Wed, 22 Nov 2017 11:31:15 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2048D42047; Wed, 22 Nov 2017 11:31:13 +0000 (GMT) Received: from skywalker (unknown [9.124.35.86]) by d06av24.portsmouth.uk.ibm.com (Postfix) with SMTP; Wed, 22 Nov 2017 11:31:12 +0000 (GMT) Received: (nullmailer pid 20171 invoked by uid 1000); Wed, 22 Nov 2017 11:36:27 -0000 From: "Aneesh Kumar K.V" To: "Kirill A. Shutemov" Cc: "Kirill A. Shutemov" , Ingo Molnar , x86@kernel.org, Thomas Gleixner , "H. Peter Anvin" , Linus Torvalds , Andy Lutomirski , Nicholas Piggin , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCHv3 2/2] x86/selftests: Add test for mapping placement for 5-level paging In-Reply-To: <20171122081147.5gjushlstmnnmlev@node.shutemov.name> References: <20171115143607.81541-1-kirill.shutemov@linux.intel.com> <20171115143607.81541-2-kirill.shutemov@linux.intel.com> <87y3myzx7z.fsf@linux.vnet.ibm.com> <20171122081147.5gjushlstmnnmlev@node.shutemov.name> Date: Wed, 22 Nov 2017 17:06:27 +0530 MIME-Version: 1.0 Content-Type: text/plain X-TM-AS-GCONF: 00 x-cbid: 17112211-0016-0000-0000-000005044F54 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112211-0017-0000-0000-000028401FBB Message-Id: <87vai2zgsk.fsf@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-22_03:,, 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=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711220157 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "Kirill A. Shutemov" writes: > On Wed, Nov 22, 2017 at 11:11:36AM +0530, Aneesh Kumar K.V wrote: >> "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. > > Feel free to move it to selftest/vm. I don't have time to test setup and > test it on Power myself, but this would be great. > How about the below? Do you want me to send this as a patch to the list? #include #include #include #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) #ifdef __powerpc64__ #define PAGE_SIZE 64*1024 /* * This will work with 16M and 2M hugepage size */ #define HUGETLB_SIZE 16*1024*1024 #else #define PAGE_SIZE 4096 #define HUGETLB_SIZE 2*1024*1024 #endif /* * >= 128TB is the hint addr value we used to select * large address space. */ #define ADDR_SWITCH_HINT (1UL << 47) #define LOW_ADDR ((void *) (1UL << 30)) #define HIGH_ADDR ((void *) (1UL << 48)) struct testcase { void *addr; unsigned long size; unsigned long flags; const char *msg; unsigned int addr_check_cond; unsigned int low_addr_required:1; unsigned int keep_mapped:1; }; static struct testcase testcases[] = { { /* * If stack is moved, we could possibly allocate * this at the requested address. */ .addr = ((void *)(ADDR_SWITCH_HINT - PAGE_SIZE)), .size = PAGE_SIZE, .flags = MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap(ADDR_SWITCH_HINT - PAGE_SIZE, PAGE_SIZE)", .low_addr_required = 1, }, { /* * 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. */ .addr = ((void *)(ADDR_SWITCH_HINT - PAGE_SIZE)), .size = 2 * PAGE_SIZE, .flags = MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap(ADDR_SWITCH_HINT - PAGE_SIZE, (2 * PAGE_SIZE))", .low_addr_required = 1, }, { /* * Exact mapping at 128TB, the area is free we should get that * even without MAP_FIXED. */ .addr = ((void *)(ADDR_SWITCH_HINT)), .size = PAGE_SIZE, .flags = MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap(ADDR_SWITCH_HINT, PAGE_SIZE)", .keep_mapped = 1, }, { .addr = (void *)(ADDR_SWITCH_HINT), .size = 2 * PAGE_SIZE, .flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, .msg = "mmap(ADDR_SWITCH_HINT, 2 * PAGE_SIZE, MAP_FIXED)", }, { .addr = NULL, .size = 2 * PAGE_SIZE, .flags = MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap(NULL)", .low_addr_required = 1, }, { .addr = LOW_ADDR, .size = 2 * PAGE_SIZE, .flags = MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap(LOW_ADDR)", .low_addr_required = 1, }, { .addr = HIGH_ADDR, .size = 2 * PAGE_SIZE, .flags = MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap(HIGH_ADDR)", .keep_mapped = 1, }, { .addr = HIGH_ADDR, .size = 2 * PAGE_SIZE, .flags = MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap(HIGH_ADDR) again", .keep_mapped = 1, }, { .addr = HIGH_ADDR, .size = 2 * PAGE_SIZE, .flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, .msg = "mmap(HIGH_ADDR, MAP_FIXED)", }, { .addr = (void*) -1, .size = 2 * PAGE_SIZE, .flags = MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap(-1)", .keep_mapped = 1, }, { .addr = (void*) -1, .size = 2 * PAGE_SIZE, .flags = MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap(-1) again", }, { .addr = ((void *)(ADDR_SWITCH_HINT - PAGE_SIZE)), .size = PAGE_SIZE, .flags = MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap(ADDR_SWITCH_HINT - PAGE_SIZE, PAGE_SIZE)", .low_addr_required = 1, }, { .addr = (void *)(ADDR_SWITCH_HINT - PAGE_SIZE), .size = 2 * PAGE_SIZE, .flags = MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap(ADDR_SWITCH_HINT - PAGE_SIZE, 2 * PAGE_SIZE)", .low_addr_required = 1, .keep_mapped = 1, }, { .addr = (void *)(ADDR_SWITCH_HINT - PAGE_SIZE / 2), .size = 2 * PAGE_SIZE, .flags = MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap(ADDR_SWITCH_HINT - PAGE_SIZE/2 , 2 * PAGE_SIZE)", .low_addr_required = 1, .keep_mapped = 1, }, { .addr = ((void *)(ADDR_SWITCH_HINT)), .size = PAGE_SIZE, .flags = MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap(ADDR_SWITCH_HINT, PAGE_SIZE)", }, { .addr = (void *)(ADDR_SWITCH_HINT), .size = 2 * PAGE_SIZE, .flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, .msg = "mmap(ADDR_SWITCH_HINT, 2 * PAGE_SIZE, MAP_FIXED)", }, }; static struct testcase hugetlb_testcases[] = { { .addr = NULL, .size = HUGETLB_SIZE, .flags = MAP_HUGETLB | MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap(NULL, MAP_HUGETLB)", .low_addr_required = 1, }, { .addr = LOW_ADDR, .size = HUGETLB_SIZE, .flags = MAP_HUGETLB | MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap(LOW_ADDR, MAP_HUGETLB)", .low_addr_required = 1, }, { .addr = HIGH_ADDR, .size = HUGETLB_SIZE, .flags = MAP_HUGETLB | MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap(HIGH_ADDR, MAP_HUGETLB)", .keep_mapped = 1, }, { .addr = HIGH_ADDR, .size = HUGETLB_SIZE, .flags = MAP_HUGETLB | MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap(HIGH_ADDR, MAP_HUGETLB) again", .keep_mapped = 1, }, { .addr = HIGH_ADDR, .size = HUGETLB_SIZE, .flags = MAP_HUGETLB | MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, .msg = "mmap(HIGH_ADDR, MAP_FIXED | MAP_HUGETLB)", }, { .addr = (void*) -1, .size = HUGETLB_SIZE, .flags = MAP_HUGETLB | MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap(-1, MAP_HUGETLB)", .keep_mapped = 1, }, { .addr = (void*) -1, .size = HUGETLB_SIZE, .flags = MAP_HUGETLB | MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap(-1, MAP_HUGETLB) again", }, { .addr = (void *)(ADDR_SWITCH_HINT - PAGE_SIZE), .size = 2 * HUGETLB_SIZE, .flags = MAP_HUGETLB | MAP_PRIVATE | MAP_ANONYMOUS, .msg = "mmap((1UL << 47), 4UL << 20, MAP_HUGETLB)", .low_addr_required = 1, .keep_mapped = 1, }, { .addr = (void *)(ADDR_SWITCH_HINT), .size = 2 * HUGETLB_SIZE, .flags = MAP_HUGETLB | MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, .msg = "mmap(ADDR_SWITCH_HINT , 2 * HUGETLB_SIZE, MAP_FIXED | MAP_HUGETLB)", }, }; static void run_test(struct testcase *test, int count) { int i; void *p; for (i = 0; i < count; i++) { struct testcase *t = test + i; p = mmap(t->addr, t->size, PROT_READ | PROT_WRITE, t->flags, -1, 0); printf("%s: %p - ", t->msg, p); if (p == MAP_FAILED) { printf("FAILED\n"); continue; } if (t->low_addr_required && p >= (void *)(1UL << 47)) printf("FAILED\n"); else { /* * Do a dereference of the address returned so that we catch * bugs in page fault handling */ *(int *)p = 10; printf("OK\n"); } if (!t->keep_mapped) munmap(p, t->size); } } 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) { if (!supported_arch()) return 0; run_test(testcases, ARRAY_SIZE(testcases)); if (argc == 2 && !strcmp(argv[1], "--run_hugetlb")) run_test(hugetlb_testcases, ARRAY_SIZE(hugetlb_testcases)); return 0; } From 1584753132205632343@xxx Wed Nov 22 08:12:40 +0000 2017 X-GM-THRID: 1584229946535540405 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread