Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2434945imm; Thu, 9 Aug 2018 12:53:27 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwoYzH6082ZOmNTnIwp6oXKh6MCt/H20KgQooRBAYzoeLEsbDCSVYsn0k8H55aIo7W9uLPx X-Received: by 2002:a62:49cf:: with SMTP id r76-v6mr3670364pfi.235.1533844407044; Thu, 09 Aug 2018 12:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533844407; cv=none; d=google.com; s=arc-20160816; b=EmAe/+l5obCg1wlbY8+KGHWJR1SHOGxDCqnJb/Hms5n2f7fRYJtycKOJF7GUSjLtnq FGqeJfMh230Pijy9HoJYiZ7dWccEJv/aaVr2XfxXVTMoeVIpbYFvqNr6c9XbPEENNMAs whEn6QWCI3fjV/j4SRT31v1T9v6ZWEshQOaqcdj2NgTfddpHLgXXgRVWuPhVQolPR0aJ uwO9lIE0NRoBLy+VRxIPY+I9wiaBLPaOPv2rCGmD19YvfXX361v8dL9zbJ/c3WUThILB 4xob+7Ta47bBR0UE2oK3ALvMM/rRbxD10e9LGuO+16kQTD2l1+3AMwGkFLEIGnwp48P/ jUCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=K0C5EfJYX/VLCol+e7qiMZZQclTTNWSM3ViZXpefC7g=; b=JwFwkQ+LsP+GuoIZJ0CGvCbZIJUOGCpxBW+cixrma4A24uYJOV1OAyrVfKSPIbblgM 5tocwRdF7iTAddlxLVxU9TyYaIp7II5mMWTAMu7TBpp7GlbHyZQMsWszfD9jp/K3YVCO 3XmrBfep7X6AXIk67/YVtAIqOFKBYzEGt4k1zvMBt/WT7XR3+EfV8KGAijhUZIwqCjF9 Kqn8DBRkGyEG4Rh6vB9Y+hgSukW6uWoecQFUHsRtzkKd6QFkWPO409IAHHEhAlrDXs07 59EOWHOYKsGxE1dV2BtAjBljrMUqhlqhKmlwoKR86fLE4EwgqqwX41P6waeunX5nN5dO 5AuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=USFvtvQW; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a62-v6si7725591pge.262.2018.08.09.12.53.10; Thu, 09 Aug 2018 12:53:27 -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; dkim=pass header.i=@chromium.org header.s=google header.b=USFvtvQW; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727129AbeHIWSi (ORCPT + 99 others); Thu, 9 Aug 2018 18:18:38 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:40163 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726931AbeHIWSi (ORCPT ); Thu, 9 Aug 2018 18:18:38 -0400 Received: by mail-pl0-f67.google.com with SMTP id s17-v6so2976687plp.7 for ; Thu, 09 Aug 2018 12:52:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=K0C5EfJYX/VLCol+e7qiMZZQclTTNWSM3ViZXpefC7g=; b=USFvtvQW/h690lHqRnCDiBy0N2VNhZy0Sp/zT7birLiM8vwiqNU8rueMnR5WJbDlZ2 c+Dkuw7n1nIpgyN8ALGyHf6cIPubuWYIHKq/JtoLsIPml3+64pCiJ+1pOxiL4Syq/qmd sOJTJuTajR6m/nYY2mwQW8Rh03BFTX6IKgXTE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=K0C5EfJYX/VLCol+e7qiMZZQclTTNWSM3ViZXpefC7g=; b=taCL2kwuDFdjRwba/jsScTLVsH9ydHcfqyKHb+tAfn5B+HbQ/fOuI0HCLaNCm4d3mZ 36aEnQ9hfdPqUw05hDyqJThEjXKIG+v431WkvuI7GHgv6LU3kyhnWnVWMo2tiU82rV4Y 9pTNBx9WML3ULja5Pb8/GLTzrwdF8R8uz/PGM+rw6JzTpDnpGzh9FaXiIYHzSXzYhF2E ymjNeOrsN9t7e6YnNKsVGVSe0pFegr61v1MKIBZoKTBY8DerTELwDv6IK+pvqFEFanLg liO2pRXyjYb0PxEke9L4XGTJUkYGGHNftkdZ0NQUFGpzsz1eWKd/lgOMSfW9OEfxtZ7U eKHQ== X-Gm-Message-State: AOUpUlEo1ByqWNDrpYC7hq6Q9g3AWGdltoswGzCdS3rob/kN72vupJMs Sq7d6brC1RPzFeA4F1dH9tXcNw== X-Received: by 2002:a17:902:b609:: with SMTP id b9-v6mr3230243pls.321.1533844337377; Thu, 09 Aug 2018 12:52:17 -0700 (PDT) Received: from ban.mtv.corp.google.com ([2620:15c:202:1:299d:6b87:5478:d28a]) by smtp.gmail.com with ESMTPSA id m15-v6sm15221205pfk.149.2018.08.09.12.52.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 Aug 2018 12:52:16 -0700 (PDT) Date: Thu, 9 Aug 2018 12:52:13 -0700 From: Brian Norris To: Stephen Boyd Cc: Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Wei-Ning Huang , Julius Werner , Samuel Holland Subject: Re: [PATCH v3 2/7] firmware: coreboot: Unmap ioregion on failure Message-ID: <20180809195211.GA137192@ban.mtv.corp.google.com> References: <20180809171722.144325-1-swboyd@chromium.org> <20180809171722.144325-3-swboyd@chromium.org> <20180809174936.GC129285@ban.mtv.corp.google.com> <153384363124.220756.3747855789935101539@swboyd.mtv.corp.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <153384363124.220756.3747855789935101539@swboyd.mtv.corp.google.com> User-Agent: Mutt/1.10.1+48 (1f3a9df87d11) (2018-07-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Thu, Aug 09, 2018 at 12:40:31PM -0700, Stephen Boyd wrote: > Quoting Brian Norris (2018-08-09 10:49:38) > > On Thu, Aug 09, 2018 at 10:17:17AM -0700, Stephen Boyd wrote: > > > Both callers of coreboot_table_init() ioremap the pointer that comes in > > > but they don't unmap the memory on failure. Both of them also fail probe > > > immediately with the return value of coreboot_table_init(), leaking a > > > mapping when it fails. Plug the leak so the mapping isn't left unused. > > > > > > Cc: Wei-Ning Huang > > > Cc: Julius Werner > > > Cc: Brian Norris > > > Cc: Samuel Holland > > > Fixes: 570d30c2823f ("firmware: coreboot: Expose the coreboot table as a bus") > > > > I suppose this is fair, since that commit introduced error paths and > > didn't clean them up. But one warning below: > > > > > Signed-off-by: Stephen Boyd > > > --- > > > drivers/firmware/google/coreboot_table.c | 3 +++ > > > 1 file changed, 3 insertions(+) > > > > > > diff --git a/drivers/firmware/google/coreboot_table.c b/drivers/firmware/google/coreboot_table.c > > > index 19db5709ae28..0d3e140444ae 100644 > > > --- a/drivers/firmware/google/coreboot_table.c > > > +++ b/drivers/firmware/google/coreboot_table.c > > > @@ -138,6 +138,9 @@ int coreboot_table_init(struct device *dev, void __iomem *ptr) > > > ptr_entry += entry.size; > > > } > > > > > > + if (ret) > > > + iounmap(ptr); > > > > This works because no sub-driver is using this mapping any more (i.e., > > because we killed coreboot_table_find()). Otherwise, we'd need to > > explicitly kill all the sub-devices first. IOW, if this gets backported > > to older kernels, it would need to go along with this and its other > > dependencies: > > The memory is copied out of the table. So do the devices actually use > the memory that we remap here? I don't see how it's a problem if we > unmap the table after we populate devices. No, the memory is (or was) copied each time. See: int coreboot_table_find(int tag, void *data, size_t data_size) { ... memcpy_fromio(&header, ptr_header, sizeof(header)); ... (where ptr_header is an alias for 'ptr') So before commit b616cf53aa7a and friends, this patch is a bad idea. Just to reiterate/clarify: none of this is a criticism of this patch as applied to mainline. It's just a criticism of what might happen with the 'Fixes' tag if we aren't careful. Brian > > b616cf53aa7a firmware: coreboot: Remove unused coreboot_table_find