From patchwork Fri Oct 27 14:21:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Dobriyan X-Patchwork-Id: 158950 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp640629vqb; Fri, 27 Oct 2023 07:21:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHcDzD6bW/CGsoBQLLKnW5jD+N+Z/4Zr7M64hOFR2Izru/Z4PAGeHSyRTjM9p2BJImFWm2o X-Received: by 2002:a05:6830:4d6:b0:6cd:896:e363 with SMTP id s22-20020a05683004d600b006cd0896e363mr2459487otd.37.1698416508403; Fri, 27 Oct 2023 07:21:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698416508; cv=none; d=google.com; s=arc-20160816; b=LyCUCLYIw8wJKr773IJdFlDuHn7c69ivL6cE6NcOchoWJ4nXHHEbRm1sqn363JAdXt IktNQMttH97HRzKUs8goqLGXWHwaDL+tk6cyzmtahhAVQfOZ8KMEFOMrga7BDlKWb0TY P+gigEBkvVGO8iuVlXBe4W7o4DozF71MPFFZtrlbFp83rmcCqYC54RZteylSxAN6L/4R Z0hyiGHnM5Epct/ONkKDAln49pgqIxb0Yyk5Ejy9aW7UhlZ5w3d6SI0unl0dtXWAPX76 IEKFF/a+FpSZV5vuz2P6P/NA8VAqC+DICNa4Yrr43+VP6PbsCrRuokDNmxQHG/T9Cc0V c+VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=Y6i8VATS6nFhEbYaXyntF8SokXtip/zVE7KgzAiMv+E=; fh=OsxpHFVO0TTWpkd9nz9iIoXNJG/cbfzAlmsmMnvz/wI=; b=IuaLFVxge6QYO0kFih6tXJRFlrU8omTl+KQDwBab6Jl05Rt0TvLJ3wz5IqYJpk6AGL PBRo261mktjVMBCOZjmIQ+PwBygGr6phis/0SPK5xbfDe1v7XJmFeBazTsYSWDl/CnFU Wlj8dfudAvCiDXRxftUPmDILWMXYJNz0dJYXVHi5vLmqPQN5A7ACS8heRu476GDLLy+s FIDfLQ4aGh5+EhC5r7l7OnWPEJsiqQ49nmSvhWtVkhHdI9285wF27Re3lL5N6qWqjvCU o0aZ8xcJ7dPX7we2bZtuT23rwtxVtr3PRixNPS3kFy171EHEOY6bwAg1ZfH3k0e9sBwR +vgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=O8LpcAaS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id s64-20020a818243000000b0058696be138dsi2687532ywf.238.2023.10.27.07.21.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 07:21:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=O8LpcAaS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id C1DEC82990DB; Fri, 27 Oct 2023 07:21:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230451AbjJ0OVe (ORCPT + 25 others); Fri, 27 Oct 2023 10:21:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346216AbjJ0OVW (ORCPT ); Fri, 27 Oct 2023 10:21:22 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E833D1AA for ; Fri, 27 Oct 2023 07:21:07 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-9becde9ea7bso688792566b.0 for ; Fri, 27 Oct 2023 07:21:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698416466; x=1699021266; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=Y6i8VATS6nFhEbYaXyntF8SokXtip/zVE7KgzAiMv+E=; b=O8LpcAaSefsQry5b0QTcPDp2H5xq+tcuw86GTFdXi+EuKJ2k5s/+h16yuGlKOhKTbF gPYPFFO2+3onCMmTa+u2iCcXB/KTcjb9cv/ksZXuV29gL290hV8PXGKywFo3dlPG9URh RmVAAO/2ihAsS3KkiMxoGF6+fNyiPSbpaQ+Me3GtLUazdLlQdZUkKaQ6+qv+z2BY5uov LG7HBSkAt0005LtEHjNs63PiGpxm3GbX2ISRexfqWd9FSa5FrQSt5ymxP3C0ba/BCP4o 53wXUXxqacRuP/7po5NqD8lb8c2tFSqG6A4sHTbX1fWbSsq3dK5gYaJZYnBU3i9tLLmY NETQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698416466; x=1699021266; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Y6i8VATS6nFhEbYaXyntF8SokXtip/zVE7KgzAiMv+E=; b=gyLDbZS+XQzcDjVJIxG1SXvzYBarzTjR+iZH1ALEZO0X+1kbcDsilSec/UxvU/iIn4 idi8pAOQVus9PSgUqos0ESuDA8/BWYI3NRmIA2fyNBl2MfywahAvH1ZvtCj9F9BlvZpc J/EE6lo0RXuqnpRKEpQNtnt5e5Tq+Ln8ik9ukDdbCSjsREOIIFUETbyIC68yVy6cNE+u rkpG01tUwzmNkoicpwYTwBT9f4qQjce1XXDuwf0NPNy+qNzJYJCbHINtftwHT2qTMlWS gCKQaOJ/Id7JtVMjv+mPCiSYl5lkdPLC+fG0zjzgqJOSg3NYZjhZP+BSOpO+4WfL2vG8 qgHg== X-Gm-Message-State: AOJu0YzBUM++LA0LQiCI8OHUHcq1+nPabBh+UqyoSBdeq0Dj49ghELau 9+BgLonWCzwl5ZVDMZwzpZnKJgFBJQ== X-Received: by 2002:a17:907:3f9f:b0:9b2:be5e:3674 with SMTP id hr31-20020a1709073f9f00b009b2be5e3674mr2926543ejc.36.1698416466036; Fri, 27 Oct 2023 07:21:06 -0700 (PDT) Received: from p183 ([46.53.253.206]) by smtp.gmail.com with ESMTPSA id ov6-20020a170906fc0600b00992e14af9c3sm1276747ejb.143.2023.10.27.07.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 07:21:05 -0700 (PDT) Date: Fri, 27 Oct 2023 17:21:03 +0300 From: Alexey Dobriyan To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/2] proc: fix proc-empty-vm test with vsyscall Message-ID: <76f42cce-b1ab-45ec-b6b2-4c64f0dccb90@p183> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 27 Oct 2023 07:21:45 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780918788643422141 X-GMAIL-MSGID: 1780918788643422141 * fix embarassing /proc/*/smaps test bug due to a typo in variable name it tested only the first line of the output if vsyscall is enabled: ffffffffff600000-ffffffffff601000 r-xp ... so test passed but tested only VMA location and permissions. * add "KSM" entry, unnoticed because (1) * swap "r-xp" and "--xp" vsyscall test strings, also unnoticed because (1) Signed-off-by: Alexey Dobriyan --- tools/testing/selftests/proc/proc-empty-vm.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/tools/testing/selftests/proc/proc-empty-vm.c +++ b/tools/testing/selftests/proc/proc-empty-vm.c @@ -60,7 +60,7 @@ static const char proc_pid_maps_vsyscall_2[] = static const char proc_pid_smaps_vsyscall_0[] = ""; static const char proc_pid_smaps_vsyscall_1[] = -"ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]\n" +"ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall]\n" "Size: 4 kB\n" "KernelPageSize: 4 kB\n" "MMUPageSize: 4 kB\n" @@ -73,6 +73,7 @@ static const char proc_pid_smaps_vsyscall_1[] = "Private_Dirty: 0 kB\n" "Referenced: 0 kB\n" "Anonymous: 0 kB\n" +"KSM: 0 kB\n" "LazyFree: 0 kB\n" "AnonHugePages: 0 kB\n" "ShmemPmdMapped: 0 kB\n" @@ -90,7 +91,7 @@ static const char proc_pid_smaps_vsyscall_1[] = ; static const char proc_pid_smaps_vsyscall_2[] = -"ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall]\n" +"ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]\n" "Size: 4 kB\n" "KernelPageSize: 4 kB\n" "MMUPageSize: 4 kB\n" @@ -103,6 +104,7 @@ static const char proc_pid_smaps_vsyscall_2[] = "Private_Dirty: 0 kB\n" "Referenced: 0 kB\n" "Anonymous: 0 kB\n" +"KSM: 0 kB\n" "LazyFree: 0 kB\n" "AnonHugePages: 0 kB\n" "ShmemPmdMapped: 0 kB\n" @@ -244,10 +246,10 @@ static int test_proc_pid_smaps(pid_t pid) if (g_vsyscall == 0) { assert(rv == 0); } else { - size_t len = strlen(g_proc_pid_maps_vsyscall); + size_t len = strlen(g_proc_pid_smaps_vsyscall); /* TODO "ProtectionKey:" */ assert(rv > len); - assert(memcmp(buf, g_proc_pid_maps_vsyscall, len) == 0); + assert(memcmp(buf, g_proc_pid_smaps_vsyscall, len) == 0); } return EXIT_SUCCESS; } From patchwork Fri Oct 27 14:26:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Dobriyan X-Patchwork-Id: 158961 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp644058vqb; Fri, 27 Oct 2023 07:27:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFX2PW4mjNUtcMVcORLl09izI142UvORkIaLJ3q6jy62Q1bXfHDQEFbGAU+l0jfemPMh0Nk X-Received: by 2002:a81:d007:0:b0:5a8:5137:b5fb with SMTP id v7-20020a81d007000000b005a85137b5fbmr3170116ywi.47.1698416823590; Fri, 27 Oct 2023 07:27:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698416823; cv=none; d=google.com; s=arc-20160816; b=ZxMGZ/uA54c1y4yViNfHGDNutvs310lUS916FUBWP5GvcKwDJ7q3TZIIiO70AcC8FS exyj7ZWo2JmX+URaBo2qwQfPPFNqBtUSuLqhy4n/IDm7JhnhmXoE/rejeLVqEGPxz9bc bn0C5KE62ONnAGZii/ARgTFz43J6+7LWucq3Q4SOsCt/HReclIfT7Ir4s1xUaV70Qhpr XS3lYTe2/0kHXMWU+SqGczDqHkTJTwAFVjwGyzr7piO7NXheGV9qPXuOoAY53cOukJiT eestCA7DpuGgkHtZEIJXdDeL3FJIwOhGTVXScMa22sbHaVE+UZj6eww95T9OYKzS1ANF WtGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Ziy+hDit/33rDQvA9Pj8jeQpZiJtdj7ZUvgfQi/0pS4=; fh=YvYhnLmI/zcvvObKNR/htIkop5tx7H9R3UPly1pVQvU=; b=iVBpWf9qGRx69Y7lUztJQ8e20UtoA8MutlmwO4khO11MRaCUd1nkteeMSOtSlcjtNv LOkSSlyLmrWwbuKewYW/7OGEb+ErQjaXx4gDKA1xvT/5qo9Ay2GdhUZEX+ymTxaLUY2E da71fvQ7r32JdBTCQQZatV2yvuG7N/EqBqcxMMHGVw+OaqmVuan90BW4mgondSitlKBH iSNBQBEbnWzXrbl5Dih75VtnJNqT/w0O9sh5Tc0UJwkkUrC4OxFnX6sKj5Z0r+QHJ5JZ F2c2LXek6fTT6VEs26IFvbfuoKrc66bgHtvM/aNwtyF0t8HKKvQioD3dGjODxAX3l0XX DiXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EAFQlb3o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id s5-20020a815e05000000b00585f76f2aadsi3144551ywb.211.2023.10.27.07.27.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 07:27:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EAFQlb3o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 7C9B983784AF; Fri, 27 Oct 2023 07:27:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345952AbjJ0O0c (ORCPT + 25 others); Fri, 27 Oct 2023 10:26:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345934AbjJ0O0b (ORCPT ); Fri, 27 Oct 2023 10:26:31 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20D13D7 for ; Fri, 27 Oct 2023 07:26:28 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-507c8316abcso2724147e87.1 for ; Fri, 27 Oct 2023 07:26:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698416786; x=1699021586; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Ziy+hDit/33rDQvA9Pj8jeQpZiJtdj7ZUvgfQi/0pS4=; b=EAFQlb3oH9MQnFszCW5meMTs0moxUlLT4W894ygT9togQQ/03ErfCBff22BnxviEBD God1WpLPhlFN26IF96qyWwqv2WVS3TL1ZlSkYNFzVyVIjJ5q2KdwagiZIyog3mGut3H0 ETxbLq+K0Mm59reD9udea2jjQXLC+bt14QswZbmyvouhsAIZ3J21ao/ABT8UMDLJiUTr bny2Sx3AdurdM+XLmQpuBv/IORo/gzUpOaQsMn4x1HaVXCsyfVZoqEO0FKfBrA9zp/FV 4Brfen1jdOPh35NWps49r5iG9bcMcQDnQsnMDZ4nKMwBCZq3VMF2FYu6N5nEzkw4dBOU waiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698416786; x=1699021586; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Ziy+hDit/33rDQvA9Pj8jeQpZiJtdj7ZUvgfQi/0pS4=; b=AWALTuK/2ijv8Y+Sxh47/4w0zoUs0Bs8nO/h4klLKH9+/zZ5tQUFj0XadjFlMiUgWK ZBWpW7el3RD4VZyamAUldEOh3RO25r2H4wMBmwFUKqmhQ+0kWhUhSODwMSm5+zSsknSZ jXBaCa50KYVOswH0bOsYM7BvI5pnubJNYH3H2hQ7OmcvuLdFQdlq2uXg+B3t5FbEnZD3 ggJajDRvriS7myMkNiMVmFmV43WyT379BnijXxno6OcdlrNQokNNBb6LtsfjeN01vFWp S1Ahw0DxI8KcrwsxahG2XjWU54bu1CBq7dygcNNggqvFtTEnyD/Hblw1hCHn+oy0ACDM lnbw== X-Gm-Message-State: AOJu0Yz3NV4nQRvPayPrJ1iic/y6KkuuEPgUgCii+ZF+UC+nU2xnZPv8 KW9OJXejCyOjyuYkQz70ETZDG3uvFA== X-Received: by 2002:ac2:4546:0:b0:507:9fe7:f321 with SMTP id j6-20020ac24546000000b005079fe7f321mr1974991lfm.54.1698416786100; Fri, 27 Oct 2023 07:26:26 -0700 (PDT) Received: from p183 ([46.53.253.206]) by smtp.gmail.com with ESMTPSA id l25-20020a1709060e1900b009c65e13c33dsm1235812eji.122.2023.10.27.07.26.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 07:26:25 -0700 (PDT) Date: Fri, 27 Oct 2023 17:26:24 +0300 From: Alexey Dobriyan To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, Swarup Laxman Kotiaklapudi Subject: [PATCH 2/2] proc: test ProtectionKey in proc-empty-vm test Message-ID: References: <76f42cce-b1ab-45ec-b6b2-4c64f0dccb90@p183> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <76f42cce-b1ab-45ec-b6b2-4c64f0dccb90@p183> X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 27 Oct 2023 07:27:00 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780919119143978644 X-GMAIL-MSGID: 1780919119143978644 From: Swarup Laxman Kotiaklapudi Check ProtectionKey field in /proc/*/smaps output, if system supports protection keys feature. [test support in the beginning of the program, use syscall, not glibc pkey_alloc(3) which may not compile, --adobriyan] Signed-off-by: Swarup Laxman Kotiaklapudi Signed-off-by: Alexey Dobriyan Reviewed-by: Swarup Laxman Kotikalapudi Tested-by: Swarup Laxman Kotikalapudi --- tools/testing/selftests/proc/proc-empty-vm.c | 79 ++++++++++++++++++++------- 1 file changed, 61 insertions(+), 18 deletions(-) --- a/tools/testing/selftests/proc/proc-empty-vm.c +++ b/tools/testing/selftests/proc/proc-empty-vm.c @@ -23,6 +23,9 @@ * /proc/${pid}/smaps * /proc/${pid}/smaps_rollup */ +#undef _GNU_SOURCE +#define _GNU_SOURCE + #undef NDEBUG #include #include @@ -34,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -42,6 +46,43 @@ #define TEST_VSYSCALL #endif +#if defined __amd64__ + #ifndef SYS_pkey_alloc + #define SYS_pkey_alloc 330 + #endif + #ifndef SYS_pkey_free + #define SYS_pkey_free 331 + #endif +#elif defined __i386__ + #ifndef SYS_pkey_alloc + #define SYS_pkey_alloc 381 + #endif + #ifndef SYS_pkey_free + #define SYS_pkey_free 382 + #endif +#else + #error "SYS_pkey_alloc" +#endif + +static int g_protection_key_support; + +static int protection_key_support(void) +{ + long rv = syscall(SYS_pkey_alloc, 0, 0); + if (rv > 0) { + syscall(SYS_pkey_free, (int)rv); + return 1; + } else if (rv == -1 && errno == ENOSYS) { + return 0; + } else if (rv == -1 && errno == EINVAL) { + // ospke=n + return 0; + } else { + fprintf(stderr, "%s: error: rv %ld, errno %d\n", __func__, rv, errno); + exit(EXIT_FAILURE); + } +} + /* * 0: vsyscall VMA doesn't exist vsyscall=none * 1: vsyscall VMA is --xp vsyscall=xonly @@ -84,10 +125,6 @@ static const char proc_pid_smaps_vsyscall_1[] = "SwapPss: 0 kB\n" "Locked: 0 kB\n" "THPeligible: 0\n" -/* - * "ProtectionKey:" field is conditional. It is possible to check it as well, - * but I don't have such machine. - */ ; static const char proc_pid_smaps_vsyscall_2[] = @@ -115,10 +152,6 @@ static const char proc_pid_smaps_vsyscall_2[] = "SwapPss: 0 kB\n" "Locked: 0 kB\n" "THPeligible: 0\n" -/* - * "ProtectionKey:" field is conditional. It is possible to check it as well, - * but I'm too tired. - */ ; static void sigaction_SIGSEGV(int _, siginfo_t *__, void *___) @@ -240,19 +273,27 @@ static int test_proc_pid_smaps(pid_t pid) } perror("open /proc/${pid}/smaps"); return EXIT_FAILURE; + } + ssize_t rv = read(fd, buf, sizeof(buf)); + close(fd); + + assert(0 <= rv); + assert(rv <= sizeof(buf)); + + if (g_vsyscall == 0) { + assert(rv == 0); } else { - ssize_t rv = read(fd, buf, sizeof(buf)); - close(fd); - if (g_vsyscall == 0) { - assert(rv == 0); - } else { - size_t len = strlen(g_proc_pid_smaps_vsyscall); - /* TODO "ProtectionKey:" */ - assert(rv > len); - assert(memcmp(buf, g_proc_pid_smaps_vsyscall, len) == 0); + size_t len = strlen(g_proc_pid_smaps_vsyscall); + assert(rv > len); + assert(memcmp(buf, g_proc_pid_smaps_vsyscall, len) == 0); + + if (g_protection_key_support) { +#define PROTECTION_KEY "ProtectionKey: 0\n" + assert(memmem(buf, rv, PROTECTION_KEY, strlen(PROTECTION_KEY))); } - return EXIT_SUCCESS; } + + return EXIT_SUCCESS; } static const char g_smaps_rollup[] = @@ -419,6 +460,8 @@ int main(void) abort(); } + g_protection_key_support = protection_key_support(); + pid_t pid = fork(); if (pid == -1) { perror("fork");