Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp684358yba; Thu, 16 May 2019 07:22:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqyp4stvfo1Imp5Csr2BTkQSkc5cWhiqR4BJJTamnnafXrqE153GkHRpF87ewxfdxbKOcV6K X-Received: by 2002:a65:57ce:: with SMTP id q14mr36803451pgr.109.1558016559268; Thu, 16 May 2019 07:22:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558016559; cv=none; d=google.com; s=arc-20160816; b=xlSaE7nbtmZCM8Ov/IGZ/t7KFjFGIaxsCqe8hqn6BZnLDmlwvWJjhx3Z5rqkzgMuVG RvdUnbG3GWobv+FN0Sb1vDEri0HQ/Uw4adUrZr+Isx+/zGg8kxXUPR58QudoD2YA9fL6 uF4rWjrcxpamiAtYyrkVEoQIp7M9/Z2SV6ndlHC3C2NAZ9Guj8zE221C/IwMGQtgTy9l 27MbiPHJWc/XCe92EEQCqpj1ysHsAmdzU2FejV5RMz8NcFfC+qcPd4sfywKOnGam0xz/ qmbyCIKbrmSQdphY+sqEEGs5DCZNCNT5V9kIoLGb6iPs4Or1FoOpfmr3BIFJFea2pLmN 24+A== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=WMJwYfQRXN5zZiAp/Xz5pPBDKxQgT8PT4EIq2U8ayD8=; b=my+dSm43HjN+8+61er0aViBJvXUfIXce5l2ydf2rLvG5Fk5qm94mODXfxLgp8e7CA8 GQfTTPQDerC2mJp74hXq8BOJRUHJCod2eByOxZGdIUFM+oHXOeqh6pDFuevrwSaIuWU5 24YPflpKLwi9lCDsTJBnvSNJPcg/JA6wSpn9ySHcMfx3cyQB0XSQzTI8xVLmtCyfMjYC CVtkvIGF3RBzzQ97/I5DTiAZtscnjD9HreWo4A/T9Ky12jfoD9KgaGk4OlcjJfjkgpEo cSXZdZSixu/yEeU5P+kqGPyib2q/t566Xrt0MunOTMjknQ28RjY4TUS4o2Caxug+QN/S wznw== 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 x28si5874673pfr.289.2019.05.16.07.22.23; Thu, 16 May 2019 07:22:39 -0700 (PDT) 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 S1726955AbfEPOVD (ORCPT + 99 others); Thu, 16 May 2019 10:21:03 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:47398 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726687AbfEPOVD (ORCPT ); Thu, 16 May 2019 10:21:03 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 599B11715; Thu, 16 May 2019 07:21:02 -0700 (PDT) Received: from [10.1.196.69] (e112269-lin.cambridge.arm.com [10.1.196.69]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 21BAB3F71E; Thu, 16 May 2019 07:21:00 -0700 (PDT) Subject: Re: Bad virt_to_phys since commit 54c7a8916a887f35 To: Mark Rutland Cc: Christoph Hellwig , linux-kernel@vger.kernel.org, Mike Rapoport , Andrew Morton , Will Deacon , Catalin Marinas References: <20190516133820.GA43059@lakrids.cambridge.arm.com> <20190516134105.GB43059@lakrids.cambridge.arm.com> <20190516141640.GC43059@lakrids.cambridge.arm.com> From: Steven Price Message-ID: Date: Thu, 16 May 2019 15:20:59 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190516141640.GC43059@lakrids.cambridge.arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16/05/2019 15:16, Mark Rutland wrote: > On Thu, May 16, 2019 at 03:05:31PM +0100, Steven Price wrote: >> On 16/05/2019 14:41, Mark Rutland wrote: >>> On Thu, May 16, 2019 at 02:38:20PM +0100, Mark Rutland wrote: >>>> Hi, >>>> >>>> Since commit: >>>> >>>> 54c7a8916a887f35 ("initramfs: free initrd memory if opening /initrd.image fails") >>> >>> Ugh, I dropped a paragarph here. >>> >>> Since that commit, I'm seeing a boot-time splat on arm64 when using >>> CONFIG_DEBUG_VIRTUAL. I'm running an arm64 syzkaller instance, and this >>> kills the VM, preventing further testing, which is unfortunate. >>> >>> Mark. >>> >>>> IIUC prior to that commit, we'd only attempt to free an intird if we had >>>> one, whereas now we do so unconditionally. AFAICT, in this case >>>> initrd_start has not been initialized (I'm not using an initrd or >>>> initramfs on my system), so we end up trying virt_to_phys() on a bogus >>>> VA in free_initrd_mem(). >>>> >>>> Any ideas on the right way to fix this? >> >> Your analysis looks right to me. In my review I'd managed to spot the >> change in behaviour when CONFIG_INITRAMFS_FORCE is set (the initrd is >> freed), but I'd overlooked what happens if initrd_start == 0 (the >> non-existent initrd is attempted to be freed). >> >> I suspect the following is sufficient to fix the problem: >> >> ----8<----- >> diff --git a/init/initramfs.c b/init/initramfs.c >> index 435a428c2af1..178130fd61c2 100644 >> --- a/init/initramfs.c >> +++ b/init/initramfs.c >> @@ -669,7 +669,7 @@ static int __init populate_rootfs(void) >> * If the initrd region is overlapped with crashkernel reserved region, >> * free only memory that is not part of crashkernel region. >> */ >> - if (!do_retain_initrd && !kexec_free_initrd()) >> + if (!do_retain_initrd && initrd_start && !kexec_free_initrd()) >> free_initrd_mem(initrd_start, initrd_end); >> initrd_start = 0; >> initrd_end = 0; > > That works for me. If you spin this as a real patch: > > Tested-by: Mark Rutland > > As I mentioned, initrd_start has not been initialized at all, so I > suspect we should also update its declaration in init/do_mounts_initrd.c > such that it is guaranteed to be initialized to zero. We get away with > that today, but that won't necessarily hold with LTO and so on... Well it's a global variable, so the C standard says it should be initialised to 0... I'll spin a real patch and add your Tested-by Steve