From patchwork Thu Feb 6 08:42:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 11367939 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8147414B4 for ; Thu, 6 Feb 2020 08:42:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4E4A222522 for ; Thu, 6 Feb 2020 08:42:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=c-s.fr header.i=@c-s.fr header.b="wkjVDANm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4E4A222522 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=c-s.fr Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 615586B0003; Thu, 6 Feb 2020 03:42:04 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 59F086B0006; Thu, 6 Feb 2020 03:42:04 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48E676B0007; Thu, 6 Feb 2020 03:42:04 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0135.hostedemail.com [216.40.44.135]) by kanga.kvack.org (Postfix) with ESMTP id 2D2D16B0003 for ; Thu, 6 Feb 2020 03:42:04 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id D7B394404 for ; Thu, 6 Feb 2020 08:42:03 +0000 (UTC) X-FDA: 76459059726.18.wire59_4c2917d646761 X-Spam-Summary: 2,0,0,19ef4dd16c04b8bc,d41d8cd98f00b204,christophe.leroy@c-s.fr,:mpe@ellerman.id.au:shuah@kernel.org:linux-kernel@vger.kernel.org:linuxppc-dev@lists.ozlabs.org::linux-kselftest@vger.kernel.org,RULES_HIT:41:355:379:800:960:973:988:989:1260:1261:1345:1437:1534:1542:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:4321:5007:6261:6653:7903:8603:8634:8660:10004:11657:11658:11914:12043:12296:12297:12555:12679:12895:13148:13161:13229:13230:14181:14394:14721:21080:21451:21627:21990:30003:30054:30056:30070,0,RBL:93.17.236.30:@c-s.fr:.lbl8.mailshell.net-62.2.5.100 64.100.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:30,LUA_SUMMARY:none X-HE-Tag: wire59_4c2917d646761 X-Filterd-Recvd-Size: 4450 Received: from pegase1.c-s.fr (pegase1.c-s.fr [93.17.236.30]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Thu, 6 Feb 2020 08:42:03 +0000 (UTC) Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 48CsP44jN9z9vC0r; Thu, 6 Feb 2020 09:42:00 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=wkjVDANm; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id 2lcOikkEyzC2; Thu, 6 Feb 2020 09:42:00 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 48CsP43hxRz9vC0n; Thu, 6 Feb 2020 09:42:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1580978520; bh=89Y1BOmA6wd1Qv1aLetSGC2roM1Y6EfmkaNgZWi44Bs=; h=From:Subject:To:Cc:Date:From; b=wkjVDANm8pbO0N3AKTilK3eCwh8bumOVKS5vfWKUrOYOvLd6ZaUIcXBSVPjSmTBF5 AxrjfEnc382MsgT0Ui6v/WgrJ5MrsZ8rI4UsEs44JCQQakGPkP1SYEk1kpDnL1SxOa dJewoePk7SdTIQO0dfgnZdaPFmr2x/li07lS00j4= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 5FC0A8B863; Thu, 6 Feb 2020 09:42:01 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id MqOjk89_hQPt; Thu, 6 Feb 2020 09:42:01 +0100 (CET) Received: from pc16570vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 0CA8F8B85F; Thu, 6 Feb 2020 09:42:01 +0100 (CET) Received: by localhost.localdomain (Postfix, from userid 0) id BCF98652B7; Thu, 6 Feb 2020 08:42:00 +0000 (UTC) Message-Id: <9a404a13c871c4bd0ba9ede68f69a1225180dd7e.1580978385.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [PATCH] selftests/vm: Fix map_hugetlb length used for testing read and write To: Michael Ellerman , Shuah Khan Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Date: Thu, 6 Feb 2020 08:42:00 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Commit fa7b9a805c79 ("tools/selftest/vm: allow choosing mem size and page size in map_hugetlb") added the possibility to change the size of memory mapped for the test, but left the read and write test using the default value. This is unnoticed when mapping a length greater than the default one, but segfaults otherwise. Fix read_bytes() and write_bytes() by giving them the real length. Also fix the call to munmap(). Fixes: fa7b9a805c79 ("tools/selftest/vm: allow choosing mem size and page size in map_hugetlb") Cc: stable@vger.kernel.org Signed-off-by: Christophe Leroy Reviewed-by: Leonardo Bras --- tools/testing/selftests/vm/map_hugetlb.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/vm/map_hugetlb.c b/tools/testing/selftests/vm/map_hugetlb.c index 5a2d7b8efc40..6af951900aa3 100644 --- a/tools/testing/selftests/vm/map_hugetlb.c +++ b/tools/testing/selftests/vm/map_hugetlb.c @@ -45,20 +45,20 @@ static void check_bytes(char *addr) printf("First hex is %x\n", *((unsigned int *)addr)); } -static void write_bytes(char *addr) +static void write_bytes(char *addr, size_t length) { unsigned long i; - for (i = 0; i < LENGTH; i++) + for (i = 0; i < length; i++) *(addr + i) = (char)i; } -static int read_bytes(char *addr) +static int read_bytes(char *addr, size_t length) { unsigned long i; check_bytes(addr); - for (i = 0; i < LENGTH; i++) + for (i = 0; i < length; i++) if (*(addr + i) != (char)i) { printf("Mismatch at %lu\n", i); return 1; @@ -96,11 +96,11 @@ int main(int argc, char **argv) printf("Returned address is %p\n", addr); check_bytes(addr); - write_bytes(addr); - ret = read_bytes(addr); + write_bytes(addr, length); + ret = read_bytes(addr, length); /* munmap() length of MAP_HUGETLB memory must be hugepage aligned */ - if (munmap(addr, LENGTH)) { + if (munmap(addr, length)) { perror("munmap"); exit(1); }