Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2588442ybv; Fri, 14 Feb 2020 22:50:19 -0800 (PST) X-Google-Smtp-Source: APXvYqyoZuM2BIWxA0YUX/eMcu+xlkR9Yw3DnI23wRvb00Ni0TeayTvx/fRHbMtscLOwmwcowNq9 X-Received: by 2002:a05:6808:191:: with SMTP id w17mr4131726oic.29.1581749418972; Fri, 14 Feb 2020 22:50:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581749418; cv=none; d=google.com; s=arc-20160816; b=djPG04RWRKaSsvePtR/hMKWsX+1zZSRZ/KqcYHhN5rzt6Qf+I+69O70eRNb2vIoNo8 5ekHeQx0KfUjlGwVLRCi+ExxrLiSKApWPr7OrWIFBbtfifsq6mlqO9v0vHkKhG8EbZpc Jz1NaWGluVogkfMpdtl5wIsl9rS555KmcWnQggk5LccDNIfcpnFCN2M9icY187pb5ZBf toBvS/2myvWVR/nsh5Z5p/7hqwwcoL+kFK/TYtRSd2PYGyGU3jvF4UqrzBAIMMXYm9oX Hej7qV93tHAjybqcGFfaGpxhmHpYO0MCawVU7DOmrt13+8WATjdpsNryFwQdYd8qFtB6 w0tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id; bh=RWKASrsEiZjbs5asd5V6/n1NTon7XNytKXCyRCXLQlw=; b=IR0L7UjCaBXsOF5JDqXMhxvTpgvfMx9uRU/05gPbybdwVT0lkDg7IvNnoMYir46yNd BxGlxBDheNnKyed6zIUfNerv0MWr/KXBGz2uVlB2Fmz7aQQ7eeyMvTu7LrtgnNI5imJd MdzUL5hqLV5X7/QYK/5jkv+H+H2wivOtqOkeX8Xu9dTWVmBDCTcOgonJRd5yupZfnbFJ zBh9d8XKNHQHxVIlmvNneK0vA7PpCtK+tCWvtFInVh8vbSzmE7GSFTa3bYyTeWb2KlS8 7zWJwf1Y1zrk/iJMCk8kSp4JFTzE6coJoKuI/w73r28rT1PlHGCkvp4Xe94VlKl5ySAF gT2Q== 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 z15si3600931oih.41.2020.02.14.22.50.04; Fri, 14 Feb 2020 22:50:18 -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 S1725963AbgBOGuB (ORCPT + 99 others); Sat, 15 Feb 2020 01:50:01 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:40600 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725799AbgBOGuB (ORCPT ); Sat, 15 Feb 2020 01:50:01 -0500 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01F6mtq3041788; Sat, 15 Feb 2020 01:49:48 -0500 Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0a-001b2d01.pphosted.com with ESMTP id 2y4qyuxrt8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 15 Feb 2020 01:49:48 -0500 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 01F6j3HL001799; Sat, 15 Feb 2020 06:49:47 GMT Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by ppma04dal.us.ibm.com with ESMTP id 2y6895hc4n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 15 Feb 2020 06:49:47 +0000 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 01F6nkbk13632184 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 15 Feb 2020 06:49:47 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E1C0F112063; Sat, 15 Feb 2020 06:49:46 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F3FD4112062; Sat, 15 Feb 2020 06:49:44 +0000 (GMT) Received: from LeoBras (unknown [9.85.178.59]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Sat, 15 Feb 2020 06:49:44 +0000 (GMT) Message-ID: <59cdcd821f794a9cbd8ab315b441a7ee2e43e431.camel@linux.ibm.com> Subject: Re: [PATCH] selftests/vm: Fix map_hugetlb length used for testing read and write From: Leonardo Bras To: Christophe Leroy , Michael Ellerman , Shuah Khan Cc: linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Date: Sat, 15 Feb 2020 03:49:38 -0300 In-Reply-To: <9a404a13c871c4bd0ba9ede68f69a1225180dd7e.1580978385.git.christophe.leroy@c-s.fr> References: <9a404a13c871c4bd0ba9ede68f69a1225180dd7e.1580978385.git.christophe.leroy@c-s.fr> Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-ZEi+P+decY37pq44DvhU" User-Agent: Evolution 3.34.3 (3.34.3-1.fc31) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-15_01:2020-02-14,2020-02-15 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 phishscore=0 priorityscore=1501 suspectscore=0 mlxlogscore=999 lowpriorityscore=0 impostorscore=0 spamscore=0 bulkscore=0 adultscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002150056 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-ZEi+P+decY37pq44DvhU Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello Christophe, thank you for the patch. On Thu, 2020-02-06 at 08:42 +0000, Christophe Leroy wrote: > 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. >=20 > Fix read_bytes() and write_bytes() by giving them the real length. >=20 > Also fix the call to munmap(). >=20 > 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(-) >=20 > diff --git a/tools/testing/selftests/vm/map_hugetlb.c b/tools/testing/sel= ftests/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)); > } > =20 > -static void write_bytes(char *addr) > +static void write_bytes(char *addr, size_t length) > { > unsigned long i; > =20 > - for (i =3D 0; i < LENGTH; i++) > + for (i =3D 0; i < length; i++) > *(addr + i) =3D (char)i; > } > =20 > -static int read_bytes(char *addr) > +static int read_bytes(char *addr, size_t length) > { > unsigned long i; > =20 > check_bytes(addr); > - for (i =3D 0; i < LENGTH; i++) > + for (i =3D 0; i < length; i++) > if (*(addr + i) !=3D (char)i) { > printf("Mismatch at %lu\n", i); > return 1; > @@ -96,11 +96,11 @@ int main(int argc, char **argv) > =20 > printf("Returned address is %p\n", addr); > check_bytes(addr); > - write_bytes(addr); > - ret =3D read_bytes(addr); > + write_bytes(addr, length); > + ret =3D read_bytes(addr, length); > =20 > /* munmap() length of MAP_HUGETLB memory must be hugepage aligned */ > - if (munmap(addr, LENGTH)) { > + if (munmap(addr, length)) { > perror("munmap"); > exit(1); > } I agree with you, it's a needed fix. FWIW: Reviwed-by: Leonardo Bras --=-ZEi+P+decY37pq44DvhU Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEMdeUgIzgjf6YmUyOlQYWtz9SttQFAl5HlIIACgkQlQYWtz9S ttS7OxAAwH0NauZuTxADtbg3X+UGv2GluaVEy2mQL3aZfSNO6caYZ7vkFMh2x7Ot JahcPBeMG0b9nw/lz3CNjVy9ZELdcFT/740aYibRRM2jyXRu3SCu3SKZj7FS/fg2 JGRTibi5yRoGnhyHIlukySLnUtPD8AE2uIqiwsmlBPqma8Ny7jZ5ngXeVf70vTG1 ofchi7BFHFmv2ujuMvj7PlKMoZVA+AzOu+bpK84kF8fb2GLPy5VdvIh1tVoIx0KW VpNJSvhJTYcBYRdh8z1/FnfMWgR9wRHl7l4GC+ArAtQQJhzcaxPR5kko2VrLn29D oxUU0CmuKGazbiJkLjD5IzLXdRs3ZD2VjZpRoTqUdZO+6rozDnt2ku4RzzTaQDQW kOiPrF3ozMPvrNXLae85q7/XZCQUpIfzib9A2D8Tbyu86XcDkigrdeD5/IuJMkR8 9VzSYuE+RYISRmwygFHWms1CXWFrmPkurMdmNuakpbKh8wDsq5uOMR24f3gAY3EK BJwaDMeMZgGMfZpjf4H/i2gpXxt+GQxDu8IXI8j7lpF1qMnRmszC4KZcC/4mzi4y 3qSnuDCbj9O3gwUqBXJJ/tghN/g376Q6DTe+J7pMEMJ4h+T9BaTflRBENV9USsLd S2S0dh0mWWiXGc0JD0cTd2haFR1OubCmhpNCJduE3ORRzvTT1xI= =oY9v -----END PGP SIGNATURE----- --=-ZEi+P+decY37pq44DvhU--