Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1226481imj; Sun, 17 Feb 2019 00:42:04 -0800 (PST) X-Google-Smtp-Source: AHgI3IbmKC0WHXgjj3Z8tLfaDg4RWekD4FypfORF6KV6HNx6U7SXOXXwk96D8cLHczW+8Nw8t52v X-Received: by 2002:a17:902:bc88:: with SMTP id bb8mr19356313plb.12.1550392924560; Sun, 17 Feb 2019 00:42:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550392924; cv=none; d=google.com; s=arc-20160816; b=q6YNyTUoEfOu6yeVe1kMgDP/AwrfQfOhOVMiQVAQnSZjWDppkKbpAGOJi9o3dx/s/E 001ncvi4RnLHBu/f4PEUspB1Uz+LxvYGu2wfhpVpIv/BpQUMZfVIlWZG9jKMYqybmVWi yozCV4M6HmYUUtNs8UEWJLelJsslxtazaAzP3FEVbBkxfY6QDMMJZwwHFe0j4w4Gd9Uk UGdsIX39IQ0Xx1qjajQV/nDSyAOou2MRxfGeHmVqyi/s7xfV0UkWLhhfQ3b6xIgiu0Yk 8eY8X9WEApRWqVSdGdjs2kC6OZPenjOvafgtqDx6C+7gVW4xOCbiLhBoLhlw0pG4Kv7/ sbFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:message-id:subject:cc:from:to :in-reply-to; bh=j/UvSGfSztz0OHdmLB77Qf8RScU3j8nSJQ5qAVHUHkE=; b=KdujjVtJvHn3cxX7px7YfUR5GLwN1kGlqXLTmGZDevgUtzNTCBa3+uE451AekRsjeC yopB21DYP+IS8BkyAo00XE8OiCCEe7cQ/loiLE6vjdHgA9GPZ78f8tKLiD+o+jN2zMSR KB8FfYnaGbN79ej2jx5yNm3vLZ8P+ZPxglfFSs8DKNEBGoAF5oEULwL2VAzfZ0dEvEQw t1TIyNGZQ9HnWTj6zcbd+cmcdAs+XYGfAUqNcUWCiuxbfShBd+EXKGd7tuWRq4dzOb3T HVQ9vf1Y5fRRfPJHj7g1xH7h/b6AOk5LEjAo3dwZL6cJRo2bStRJfPH98fOwmWlMxWQi PcJQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i11si1534134plt.280.2019.02.17.00.41.48; Sun, 17 Feb 2019 00:42:04 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727431AbfBQIVj (ORCPT + 99 others); Sun, 17 Feb 2019 03:21:39 -0500 Received: from ozlabs.org ([203.11.71.1]:36615 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725810AbfBQIVj (ORCPT ); Sun, 17 Feb 2019 03:21:39 -0500 Received: by ozlabs.org (Postfix, from userid 1034) id 442Khx2lFLz9sDX; Sun, 17 Feb 2019 19:21:37 +1100 (AEDT) X-powerpc-patch-notification: thanks X-powerpc-patch-commit: a58007621be33e9f7c7bed5d5ff8ecb914e1044a X-Patchwork-Hint: ignore In-Reply-To: <20190214062339.7139-1-mpe@ellerman.id.au> To: Michael Ellerman , linuxppc-dev@ozlabs.org From: Michael Ellerman Cc: linux-mm@kvack.org, erhard_f@mailbox.org, jack@suse.cz, aneesh.kumar@linux.vnet.ibm.com, linux-kernel@vger.kernel.org Subject: Re: powerpc/64s: Fix possible corruption on big endian due to pgd/pud_present() Message-Id: <442Khx2lFLz9sDX@ozlabs.org> Date: Sun, 17 Feb 2019 19:21:37 +1100 (AEDT) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2019-02-14 at 06:23:39 UTC, Michael Ellerman wrote: > In v4.20 we changed our pgd/pud_present() to check for _PAGE_PRESENT > rather than just checking that the value is non-zero, e.g.: > > static inline int pgd_present(pgd_t pgd) > { > - return !pgd_none(pgd); > + return (pgd_raw(pgd) & cpu_to_be64(_PAGE_PRESENT)); > } > > Unfortunately this is broken on big endian, as the result of the > bitwise && is truncated to int, which is always zero because > _PAGE_PRESENT is 0x8000000000000000ul. This means pgd_present() and > pud_present() are always false at compile time, and the compiler > elides the subsequent code. > > Remarkably with that bug present we are still able to boot and run > with few noticeable effects. However under some work loads we are able > to trigger a warning in the ext4 code: > > WARNING: CPU: 11 PID: 29593 at fs/ext4/inode.c:3927 .ext4_set_page_dirty+0x70/0xb0 > CPU: 11 PID: 29593 Comm: debugedit Not tainted 4.20.0-rc1 #1 > ... > NIP .ext4_set_page_dirty+0x70/0xb0 > LR .set_page_dirty+0xa0/0x150 > Call Trace: > .set_page_dirty+0xa0/0x150 > .unmap_page_range+0xbf0/0xe10 > .unmap_vmas+0x84/0x130 > .unmap_region+0xe8/0x190 > .__do_munmap+0x2f0/0x510 > .__vm_munmap+0x80/0x110 > .__se_sys_munmap+0x14/0x30 > system_call+0x5c/0x70 > > The fix is simple, we need to convert the result of the bitwise && to > an int before returning it. > > Thanks to Jan Kara and Aneesh for help with debugging. > > Fixes: da7ad366b497 ("powerpc/mm/book3s: Update pmd_present to look at _PAGE_PRESENT bit") > Cc: stable@vger.kernel.org # v4.20+ > Reported-by: Erhard F. > Reviewed-by: Aneesh Kumar K.V > Signed-off-by: Michael Ellerman Applied to powerpc fixes. https://git.kernel.org/powerpc/c/a58007621be33e9f7c7bed5d5ff8ecb9 cheers