From mboxrd@z Thu Jan 1 00:00:00 1970 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=-1.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS autolearn=unavailable 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 A150EC4360F for ; Mon, 25 Mar 2019 09:59:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6FBF820870 for ; Mon, 25 Mar 2019 09:59:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730537AbfCYJ7l (ORCPT ); Mon, 25 Mar 2019 05:59:41 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:5186 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730250AbfCYJ7k (ORCPT ); Mon, 25 Mar 2019 05:59:40 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id C9F4FB21A0DF1DDCA60A; Mon, 25 Mar 2019 17:59:36 +0800 (CST) Received: from [127.0.0.1] (10.202.227.238) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.408.0; Mon, 25 Mar 2019 17:59:26 +0800 Subject: Re: [PATCH v2 2/3] lib: logic_pio: Reject access to unregistered CPU MMIO regions To: Andy Shevchenko References: <1553105650-28012-1-git-send-email-john.garry@huawei.com> <1553105650-28012-3-git-send-email-john.garry@huawei.com> CC: Bjorn Helgaas , "Rafael J. Wysocki" , Arnd Bergmann , Lorenzo Pieralisi , Borislav Petkov , Guenter Roeck , Linux Kernel Mailing List , , Kefeng Wang , Linuxarm , Alexander Graf From: John Garry Message-ID: <3e638993-9541-1ed7-743b-5c2ddba4104e@huawei.com> Date: Mon, 25 Mar 2019 09:59:18 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.227.238] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/03/2019 19:15, Andy Shevchenko wrote: > On Wed, Mar 20, 2019 at 8:14 PM John Garry wrote: >> >> Currently when accessing logical indirect PIO addresses in >> logic_{in, out}{,s}, we first ensure that the region is registered. >> >> However, no such check exists for CPU MMIO regions. The CPU MMIO regions >> would be registered by the PCI host (when PCI_IOBASE is defined) in >> pci_register_io_range(). >> >> We have seen scenarios when systems which don't have a PCI host or, they >> do, and the PCI host probe fails, that certain devices attempts to still >> attempt to access PCI IO ports; examples are in [1] and [2]. >> >> And even though we would protect against this by ensuring the driver call >> request_{muxed_}region(), some don't do this: >> > Hi Andy, > >> #if defined(CONFIG_INDIRECT_PIO) && defined(PCI_IOBASE) >> +#define INVALID_RANGE(range) (!range || \ >> + (range->flags == LOGIC_PIO_CPU_MMIO && !range->ops)) > > It would be better to read in a form > #define foo(x) \ Sure, I can change that if you think it reads better. > (...) > >> + ret = range->ops->in(range->hostdata, \ >> + addr, sizeof(type)); \ > > Can it fit one line? It should be ok. I can shorten some variable names. > Thanks for checking, John