Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1263401ybv; Thu, 6 Feb 2020 00:43:15 -0800 (PST) X-Google-Smtp-Source: APXvYqyGCnkotxIc99e3Wz9wXdy6DA/H18qrLecUpt0L/rHQHgn8bE0mOQg3bV8BUMjQXx8jvlp3 X-Received: by 2002:a9d:66ca:: with SMTP id t10mr28996659otm.352.1580978595339; Thu, 06 Feb 2020 00:43:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580978595; cv=none; d=google.com; s=arc-20160816; b=i2UDqpoc/pRlfxn61bpX0je6GrBzmy0Tei+wwUJg2BsWD9oTMmi4DAjeqSJbPJBr6u 04dArenEImhRY8guw2QIdX5FwCPnIWeBOf9gstbe7voGYbg25WvLxu98Nq8kGMQ0DRzE IAskFMoLhNTh/zzRCjFYl5B0q2ypBHuVe1wt4ZJ15Gi81yyfcw7QRN2t9ceaqRBgGBPO MCAFWDyN4TVndfzFQKQGhgZ8rGxsUE32+sOv7RESt6MUKzyRdE50c57x3xyoPF85LD7r mHZglHbkX5Ns1UXxm5KDMXc2o5FLU+lQwsvyZz5eNlBJAsX/kHd280Rj644L7BLNIdvk HRTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:message-id :dkim-signature; bh=89Y1BOmA6wd1Qv1aLetSGC2roM1Y6EfmkaNgZWi44Bs=; b=T8a6kMiwDbnIu49F9xQY9SyCDutGmbBwgPVE0eRhF/c3mrFuRplsY6TLnvOVFUsfZb D8vbtWNr8LrkyZQb019rSYqnrHu0aa4HtEOSY0X+oMENceUbppdzZchVyJI0bQrNa0uN EMnyRHkMje1Xh+2uyxgjyJP82lXi0dTH7xFkrvIjnSB5nYGIgNteGCvUAKFkrA2QDu8t jZpktxAPkUkjzNlKo1CxoFqLcy4HcEspAG0sv/U/jgCxiohep/ph2gzIvPlsZLedaC0A QqZdpbjcAeuV+JkupoaQW7LSydKQe/D7kU4vxx5S37v6hOwwwnkIqsTpVgE+sUhla4N0 o/PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=wkjVDANm; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x20si1773580oix.155.2020.02.06.00.43.03; Thu, 06 Feb 2020 00:43:15 -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; dkim=pass header.i=@c-s.fr header.s=mail header.b=wkjVDANm; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728156AbgBFImG (ORCPT + 99 others); Thu, 6 Feb 2020 03:42:06 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:20629 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728047AbgBFImD (ORCPT ); Thu, 6 Feb 2020 03:42:03 -0500 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) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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); } -- 2.25.0