From patchwork Wed Aug 5 15:52:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 247474 Delivered-To: patch@linaro.org Received: by 2002:a92:cc90:0:0:0:0:0 with SMTP id x16csp838015ilo; Wed, 5 Aug 2020 13:09:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywb1VGSkoi9TyJ1uwvscN9uXjwr82yyRMvqtY7vg5cTijfDTDvfB9uIOyTtlmWp0RmjZPN X-Received: by 2002:a17:906:8595:: with SMTP id v21mr1003328ejx.347.1596658180196; Wed, 05 Aug 2020 13:09:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596658180; cv=none; d=google.com; s=arc-20160816; b=uAl5TiG8iau0Ey1zpJlC04I8a93DADhtwKVvP+jqRm2siC+lG9ZpDZmFY1D+r97qYy RDizefaUoe9EftIl2bIQp3F0+hOjv4/hljqAw3Zp/sn7Z4+ZjmlZ+lVRIa93HU8kzx8c KIb8qdV5SRzQhKn5ihR2KwYVCajVeEfNoZCD3Rru1H9rLl5PWvPLB9XGqRnyIozdx/gE sF28HSBoYMMzepJx4/6PqX6Fni3cjklMr5M4ElxWvrRXCi2lVvY2muCuYXGD4TQWiblI ze4wW99asBWeq1ZRaG6pG9qD1d7K8hbJVkPpnhtxukSyeYsbkAgG0iCDXuZoMw1AdNv4 N3lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4WfMajKQLpxzlXMBTtyzdOpOTWoGUQGSArIG5o+qDu8=; b=chiAKAsCyf1iLf61AoYTYS8xffpacMSw0z7but3AOalcM5lGiSrN33uDLvwQsDkbQw I9Phs9d64kCAZMwfDOTlmtnyvYWXXL62Uvi3SpIlaEbYy+FqKI8J9rLAzRz2reWvZK0H K/xSg8z9ctxm+T0c1Xdd5K4SHc8p3J1zCHUxoOKrpTa1OSmGe5j116H3VJwUq8BDMAam 3AWICKvf4qtA2iy4bAS6O8Yp2DKXQ4kWZG5UumIOZF5TZmXPQIB1Qhp0RrYpKm6Wb/vV nnYfVFoQTjADt7cPb7c04PCGJSItKD7irBJH+OqjCuOih/s9QuNo+IW6je5btuu4MvIt QQYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=t9Ylgpvi; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w14si1950583ejb.720.2020.08.05.13.09.40; Wed, 05 Aug 2020 13:09:40 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=t9Ylgpvi; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726233AbgHEUJi (ORCPT + 15 others); Wed, 5 Aug 2020 16:09:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:49470 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726883AbgHEQcO (ORCPT ); Wed, 5 Aug 2020 12:32:14 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 58E9423371; Wed, 5 Aug 2020 15:52:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596642763; bh=47QAnSMoOVMr8QHQNgdXK4N904/7dAfTkxp4OLgXePU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t9Ylgpvi0YEcEmP+ExJf6FzmK0zYUsWdnnijU1WxDn/qBN7+I0V0uDNvN/s3dDEyR m4voc3+kBHhPqCjCD58CaFVWWeVlOsrpOUGgHH1yIM2jFx0uGpPqdpV040UPJbYaLd i/7UTZxWg8Y0MmNm71zSMxMwaL+3IO7sgv960rlo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Grygorii Strashko , Linus Torvalds Subject: [PATCH 5.4 2/9] ARM: percpu.h: fix build error Date: Wed, 5 Aug 2020 17:52:39 +0200 Message-Id: <20200805153507.166338238@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200805153507.053638231@linuxfoundation.org> References: <20200805153507.053638231@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Grygorii Strashko commit aa54ea903abb02303bf55855fb51e3fcee135d70 upstream. Fix build error for the case: defined(CONFIG_SMP) && !defined(CONFIG_CPU_V6) config: keystone_defconfig CC arch/arm/kernel/signal.o In file included from ../include/linux/random.h:14, from ../arch/arm/kernel/signal.c:8: ../arch/arm/include/asm/percpu.h: In function ‘__my_cpu_offset’: ../arch/arm/include/asm/percpu.h:29:34: error: ‘current_stack_pointer’ undeclared (first use in this function); did you mean ‘user_stack_pointer’? : "Q" (*(const unsigned long *)current_stack_pointer)); ^~~~~~~~~~~~~~~~~~~~~ user_stack_pointer Fixes: f227e3ec3b5c ("random32: update the net random state on interrupt and activity") Signed-off-by: Grygorii Strashko Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- arch/arm/include/asm/percpu.h | 2 ++ 1 file changed, 2 insertions(+) --- a/arch/arm/include/asm/percpu.h +++ b/arch/arm/include/asm/percpu.h @@ -5,6 +5,8 @@ #ifndef _ASM_ARM_PERCPU_H_ #define _ASM_ARM_PERCPU_H_ +#include + /* * Same as asm-generic/percpu.h, except that we store the per cpu offset * in the TPIDRPRW. TPIDRPRW only exists on V6K and V7 From patchwork Wed Aug 5 15:52:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 266755 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 991CAC433DF for ; Wed, 5 Aug 2020 20:02:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6AEFC2076E for ; Wed, 5 Aug 2020 20:02:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596657744; bh=gXEwiYtWJrb+EFFUrwnNNz7Jzhi9gU+IQFe3eDUXoAg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=rd5+6PKmIR1fXUpX6J9S2D4/BULy8XOF3UJdQcnOqCx67QTptyuyrFcKaq7WGksCQ 7sOPZcAmWUNH2fvLzdOkiWkAfnq5Nfu/T8/+gn/jcSCQw8vjFvt9VJYRnme6H1JdVy SJun+GNehqdwDGUi5KIn5iHYI4XHjwOHtK6DH1B4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727791AbgHEUCX (ORCPT ); Wed, 5 Aug 2020 16:02:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:50656 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727879AbgHEQii (ORCPT ); Wed, 5 Aug 2020 12:38:38 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EE27223372; Wed, 5 Aug 2020 15:52:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596642766; bh=gXEwiYtWJrb+EFFUrwnNNz7Jzhi9gU+IQFe3eDUXoAg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M2FML+7vt+4ZuatgMS0dxw3DFX7U5EOcrC6nLZaM9+maUBxnrwCVXKkBXtIAgk9Aa j2+B2+8nPSvRhoYd73BZQZNbLQ+73OmEdJEuc2zwIK3bIaNwCTLct2Wm9PIoVCq4nW BfcyGtWKv2hwNXvtmK/BjTaLUkg7wqbgDy8rSwAk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?utf-8?q?Daniel_D=C3=ADaz?= , Kees Cook , Marc Zyngier , Stephen Rothwell , Willy Tarreau , Linus Torvalds Subject: [PATCH 5.4 3/9] random: fix circular include dependency on arm64 after addition of percpu.h Date: Wed, 5 Aug 2020 17:52:40 +0200 Message-Id: <20200805153507.215146082@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200805153507.053638231@linuxfoundation.org> References: <20200805153507.053638231@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Willy Tarreau commit 1c9df907da83812e4f33b59d3d142c864d9da57f upstream. Daniel Díaz and Kees Cook independently reported that commit f227e3ec3b5c ("random32: update the net random state on interrupt and activity") broke arm64 due to a circular dependency on include files since the addition of percpu.h in random.h. The correct fix would definitely be to move all the prandom32 stuff out of random.h but for backporting, a smaller solution is preferred. This one replaces linux/percpu.h with asm/percpu.h, and this fixes the problem on x86_64, arm64, arm, and mips. Note that moving percpu.h around didn't change anything and that removing it entirely broke differently. When backporting, such options might still be considered if this patch fails to help. [ It turns out that an alternate fix seems to be to just remove the troublesome remove from the arm64 that causes the circular dependency. But we might as well do the whole belt-and-suspenders thing, and minimize inclusion in too. Either will fix the problem, and both are good changes. - Linus ] Reported-by: Daniel Díaz Reported-by: Kees Cook Tested-by: Marc Zyngier Fixes: f227e3ec3b5c Cc: Stephen Rothwell Signed-off-by: Willy Tarreau Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- include/linux/random.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/include/linux/random.h +++ b/include/linux/random.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include From patchwork Wed Aug 5 15:52:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 266761 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F6E9C433E0 for ; Wed, 5 Aug 2020 16:37:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 479DF22D2B for ; Wed, 5 Aug 2020 16:37:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596645426; bh=Ay7NDJotRdX5nAKsHdNIbwNYUuB+c5ohUH5YtNPcCXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ZneTBsLMwhmF2fAz+KXKAGUJtO58z/f4gQSscvFrRbbR2/c5xtGWU/Nt1JANoYk0O BXoVcEmrq8Zg7IZyQQm21CMsvMPuazmTD32ESjnZ2Dju5Z3jT3OYND8GYUdcpkATbe 4A+PC48tiC8rcBRJE1sLpH+zeEceSrB0b9cGsCWw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727827AbgHEQgs (ORCPT ); Wed, 5 Aug 2020 12:36:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:50766 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726338AbgHEQfD (ORCPT ); Wed, 5 Aug 2020 12:35:03 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3FBEB23383; Wed, 5 Aug 2020 15:52:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596642776; bh=Ay7NDJotRdX5nAKsHdNIbwNYUuB+c5ohUH5YtNPcCXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=THejFUUXbfZKiHQndQQ8xe8uZ8KL1C8JKMrUtGvLnMQjKONDJWLbjn05VCcDCfUR6 CjieUOt+84U1E0hU/rU6W7ndMtWSoAxvJsiaSItPK2tGqpWF7FZnYKKJhyz3zk7i/F q2xO5ZJWFJ5mo147yJAhlyMzqCo6l8Y5PAqOGEAI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Kara , Wang Long , Jiang Ying Subject: [PATCH 5.4 7/9] ext4: fix direct I/O read error Date: Wed, 5 Aug 2020 17:52:44 +0200 Message-Id: <20200805153507.390841715@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200805153507.053638231@linuxfoundation.org> References: <20200805153507.053638231@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jiang Ying This patch is used to fix ext4 direct I/O read error when the read size is not aligned with block size. Then, I will use a test to explain the error. (1) Make a file that is not aligned with block size: $dd if=/dev/zero of=./test.jar bs=1000 count=3 (2) I wrote a source file named "direct_io_read_file.c" as following: #include #include #include #include #include #include #include #define BUF_SIZE 1024 int main() { int fd; int ret; unsigned char *buf; ret = posix_memalign((void **)&buf, 512, BUF_SIZE); if (ret) { perror("posix_memalign failed"); exit(1); } fd = open("./test.jar", O_RDONLY | O_DIRECT, 0755); if (fd < 0){ perror("open ./test.jar failed"); exit(1); } do { ret = read(fd, buf, BUF_SIZE); printf("ret=%d\n",ret); if (ret < 0) { perror("write test.jar failed"); } } while (ret > 0); free(buf); close(fd); } (3) Compile the source file: $gcc direct_io_read_file.c -D_GNU_SOURCE (4) Run the test program: $./a.out The result is as following: ret=1024 ret=1024 ret=952 ret=-1 write test.jar failed: Invalid argument. I have tested this program on XFS filesystem, XFS does not have this problem, because XFS use iomap_dio_rw() to do direct I/O read. And the comparing between read offset and file size is done in iomap_dio_rw(), the code is as following: if (pos < size) { retval = filemap_write_and_wait_range(mapping, pos, pos + iov_length(iov, nr_segs) - 1); if (!retval) { retval = mapping->a_ops->direct_IO(READ, iocb, iov, pos, nr_segs); } ... } ...only when "pos < size", direct I/O can be done, or 0 will be return. I have tested the fix patch on Ext4, it is up to the mustard of EINVAL in man2(read) as following: #include ssize_t read(int fd, void *buf, size_t count); EINVAL fd is attached to an object which is unsuitable for reading; or the file was opened with the O_DIRECT flag, and either the address specified in buf, the value specified in count, or the current file offset is not suitably aligned. So I think this patch can be applied to fix ext4 direct I/O error. However Ext4 introduces direct I/O read using iomap infrastructure on kernel 5.5, the patch is commit ("ext4: introduce direct I/O read using iomap infrastructure"), then Ext4 will be the same as XFS, they all use iomap_dio_rw() to do direct I/O read. So this problem does not exist on kernel 5.5 for Ext4. >From above description, we can see this problem exists on all the kernel versions between kernel 3.14 and kernel 5.4. It will cause the Applications to fail to read. For example, when the search service downloads a new full index file, the search engine is loading the previous index file and is processing the search request, it can not use buffer io that may squeeze the previous index file in use from pagecache, so the serch service must use direct I/O read. Please apply this patch on these kernel versions, or please use the method on kernel 5.5 to fix this problem. Fixes: 9fe55eea7e4b ("Fix race when checking i_size on direct i/o read") Reviewed-by: Jan Kara Co-developed-by: Wang Long Signed-off-by: Wang Long Signed-off-by: Jiang Ying Signed-off-by: Greg Kroah-Hartman --- fs/ext4/inode.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3836,6 +3836,11 @@ static ssize_t ext4_direct_IO_read(struc struct inode *inode = mapping->host; size_t count = iov_iter_count(iter); ssize_t ret; + loff_t offset = iocb->ki_pos; + loff_t size = i_size_read(inode); + + if (offset >= size) + return 0; /* * Shared inode_lock is enough for us - it protects against concurrent